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.

9 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.

12 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