So. I was working with this code:
public function front(?string $sortBy,
?string $time,
?string $type,
?string $filter,
string $federation,
Request $request): Response
{
$user = $this->getUser();
if (!$user)
{
$filter = 'all';
}
$criteria = new EntryPageView($this->getPageNb($request));
$criteria->showSortOption($criteria->resolveSort($sortBy))
… and so on; the function continues. VSCode told me there was a syntax error on the close brace on the if statement. I stared at it for a while, then pasted the code into GPT (not Copilot). Here’s the conversation we had about it:
Me
What’s the syntax error here?
(and I pasted the code)
GPT
The syntax error in your PHP function public function front seems to be due to the incorrect placement of the closing curly brace for the if statement. It appears that the if statement is not properly closed before the $criteria initialization begins. The corrected code should look like this:
public function front(?string $sortBy, ?string $time, ?string $type, ?string $filter, string $federation, Request $request): Response
{
$user = $this->getUser();
if (!$user) {
$filter = 'all';
} // Closing brace for the if statement
$criteria = new EntryPageView($this->getPageNb($request));
$criteria->showSortOption($criteria->resolveSort($sortBy));
// ... rest of your function code ...
}
Ensure that each statement and block is properly closed and followed correctly by the next statement. This corrected structure should resolve the syntax error you are encountering.
Me
I don’t get it. I put a closing curly brace right after the statement in mine… what am I missing?
GPT
I apologize for the confusion. Upon re-examining your code, it seems the placement of the curly brace is correct. If you’re still encountering a syntax error, it may not be related to the if statement structure.
Let’s look at other possible issues:
… and so on. Pasting GPT’s recommended if-statement block, including the curly brace that was already there, fixed the error. I have since re-pasted the same thing I initially gave to GPT to VSCode, and it all works now, and asking the exact same question of GPT again now leads to random guesses which have nothing to do with the cursed curly brace that was previously causing problems for both VSCode and GPT.
I have given up and moved on at this point, content to say vaguely that maybe the unusual brace style, or pasting the incomplete function without semicolon or final close brace, managed to coincidentally confuse GPT on exactly the same line where VSCode had gotten confused for unexplained reasons. But the whole thing still has this Twilight-Zone oddness to me.
All things programming and coding related. Subcommunity of Technology.
This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
Off the bat: have you checked for hidden Unicode characters?
That would be something that could throw an error in a syntax highlighter, and get the same error detected in an AI looking at the raw text… that would then proceed to fix it… and agree that the curly brace was correct [but the extra hidden character was not, which you didn’t ask it about].
GPT’s response parts that would hint at this:
As for your follow up question, is where you got a confusing answer:
Not the best prompt. Keep in mind you’re talking to a virtual slave, not a person who can go off-topic to asses the emotional implications of “I don’t get it”, then go back to explaining things in detail; if “you [the almighty humany] don’t get it”, then it’s likely to assume it’s mistaken and avoid any unpleasant confrontation (it’s been
beaten downfine-tuned into “PC underdog” mode).Better ask it something direct like: “Explain what changes have you made to the code”, or “Explain how the curly brace was not correctly placed in the original code”… but there is a chance an invalid invisible Unicode character could’ve been filtered out from the AI’s status… so even better yet, ask for explanations in the first prompt, like: “What’s the syntax error here? Explain your reasoning step by step”
Yeah, Unicode was one thing that occurred to me. I pasted the code into emacs and did hexl-mode, and literally looked character by character to see if something hinky had made its way into the code somehow. Nothing.
I went back and used the edit-and-resubmit feature to try this way. Starting from the quoted pieces I gave you before:
Me
Explain what changes have you made to the code.
GPT
Certainly! Here’s an explanation of the changes I made to the code snippet you provided:
Original Issue: In your original code, the if statement checking for the absence of $user (if (!$user)) was not properly closed. This meant that the following line of code ($criteria = new EntryPageView($this->getPageNb($request));) was being treated as part of the if block.
Change Made: I added a closing curly brace (}) right after the line $filter = ‘all’;. This properly closes the if block. With this change, the if statement now correctly encapsulates only the logic intended for when $user is not set.
To summarize, the change was purely structural, aimed at correcting a syntax error without altering the logic or behavior of your function.
Here, I think it is relevant that the LLM is going to want to continue the Markov chain so to speak – I think whatever you give it, once the die is cast in terms of a “System”-tagged explanation of the fix, it’s going to be inclined to go with the flow, either hallucinating an explanation for you, or going with the flow of your objection and agreeing with the objection if it’s plausible.
I tried another that was as neutral as I could make it:
… and it requoted my code at me again, and then admitted that there wasn’t an actual problem with it. But again, evaluating the code the first time around also works for me now, so that doesn’t mean too much. I think any opportunity to dig into what was going on has been lost at this point.
Again, this is all just LLM weirdness; I’m not surprised that the LLM looked at code and got something wrong. I’m surprised that VSCode got it wrong, in exactly the same spot that the LLM without any prompting also insisted there was an error. That’s weird.
That’s weird indeed.
Is there a possible malformed Unicode that could be lost when pasted to emacs, but not when pasted to GPT…? Nothing comes to mind, but who knows. I’ve been messing with Unicode as of late, and there are some really weird behaviors out there when using malformed strings; some software will let them through, some will error out, some will fix them transparently.
GPT is definitely going to try to follow your prompt and hallucinate anything; other than some very specific guardrails, it’s really willing to take any prompt as an undisputable source of truth… which is good in a sense, but makes it totally unsuitable as an oracle.
I’d be really surprised to learn Copilot was being used for syntax highlighting… but maybe there is some pilot test going on? Haven’t heard of any, though.
Too bad it’s no longer reproducible, could’ve been interesting.