Is this an AI hallucination or my misunderstanding of Julia syntax?

Just starting with Julia/VSCode - new to both so not quite sure where best to post this question.
I have an “invalid identifier” error in my first program which is diagnosed by GitHub CoPilot as below.
I suspect this is a “hallucination” - am I correct or am I misunderstanding something?
If it is a hallucination, should I report it, and if so to GitHub or Julia?
Many thanks!

@workspace /explain invalid identifier

 The error "invalid identifier" is likely caused by the line:

squb += 2ub + 1

In Julia, you need to explicitly use the multiplication operator `*` between numbers and variables. So `2ub` is invalid; it should be `2 * ub`.

Here's the corrected line:

// ...existing code...

if (n > squb)

ub += 1

squb += 2 * ub + 1

end #

// ...existing code...

**Gotcha:**
Julia does not allow implicit multiplication between numbers and variables (unlike some math notation). Always use `*` for multiplication.

Let me know if you see this error elsewhere or need further help!
1 Like

This is false.

Developers of the original software can’t do anything about what Copilot learned to parrot. Most you can do is discuss it in a community, which won’t begin to fix Copilot’s outputs either. Unfortunately we’re personally responsible for factchecking generative AI, which isn’t great when you’re learning the language and its Manual is unwieldy.

11 Likes

In your case, you are correct and Copilot is wrong.

However, I recommend to only, if ever, use such syntax with a single literal number prepending a single variable. Once it’s two compound expressions juxtaposed, hard to know in advance if that’ll work.

julia> x = 3
3

julia> 4(x+1)
16

julia> (x+1)4
ERROR: ParseError:
# Error @ REPL[2]:1:6
(x+1)4
#    ╙ ── extra tokens after end of expression

julia> y = 4
4

julia> (x+1)y
16

julia> y(x+1)
ERROR: MethodError: objects of type Int64 are not callable
Maybe you forgot to use an operator such as *, ^, %, / etc. ?
3 Likes

This is very easy to check yourself. Just try it in the REPL.

I wouldn’t even call this a ‘bug’ in Copilot. Making up incorrect bullshit is just what LLMs do.

13 Likes

this may help somewhat: Adding repository custom instructions for GitHub Copilot - GitHub Docs

I tested several LLMs with this simple question: Is this valid Julia syntax? x=2; y=3x

These ones responded with the correct answer (valid syntax): ChatGPT (O3), ChatGPT (4o), Gemini (2.5 Pro), DeepSeek (V3-0324), DeepSeek (R1-0528).

But Gemini (2.5 Flash) gave a wrong answer, confidently telling me that the syntax is invalid.

BTW, DeepSeek R1’s “thoughts” ended with a few surprisingly lines:

Let me double-check with the Julia parser:

julia> Meta.parse("x=2; y=3x")
This returns an expression without error.

Therefore, the answer is yes.

(Obviously, the LLM cannot type into a Julia session.)

2 Likes

Didn’t read all of the specifics. The various AI models and agent tools that actually integrate with your code have different capabilities. In my experience, Copilot is far the worst of the lot. I have had decent experience using (in no particular order of merit) Cursor, Claude Code (terminal-based), and Augment within VS Code. All three can “figure out” Julia code and do simple focused things though not always with perfect results. In my own experience, Augment is far and away the best at “understanding” existing code and making suggestions or following “orders” with reasonable success rate (say 70%). Augment can often “understand” Julia’s error messages. In general, if the AI suggestions have gone seriously awry, which can certainly happen, don’t go down the rabbit hole with it. Pull back out. Work on the code some more yourself and then give AI very small, narrow tasks to do. Also, all 3 have ways to upload (or just type in) a kind of project guidance markdown set of guidelines you want the agent to follow. Enables a lot so best to look at some examples. It is VERY worthwhile to do this so the “agent” understands what you expect.

Augment can create or modify code, run it, and evaluate output. It is pretty shocking. Actually so can Claude Code though you may or may not find it easy to follow what is going on in the terminal.

2 Likes