Julia: ERROR: syntax: Invalid character literal is ambiguous

Created on 9 Nov 2018  ·  3Comments  ·  Source: JuliaLang/julia

I've been using Julia for a month now and switch between many languages. Two of the other langauges i use quite a bit are SQL and python, languages that support single-quote strings. Obviously i know strings are defined using " double-quotes in Julia, but sometimes I slip up and define a string using ' rather than ". It would be nice in these situations to return a slightly more useful error than the current one.

'this is intended to be string' #< throws ERROR: syntax: Invalid character literal

improvement

'this is intended to be string' # ERROR: syntax: char length greater than 1 (or something)
error handling help wanted parser

Most helpful comment

'\' is just incomplete input, since we haven't seen the closing ' yet. It behaves just like f( or '.

For the original issue, it would be easy to give a more specific message like "character literal contains multiple characters".

All 3 comments

It's not really about the char length though:

julia> '\u2200'
'∀': Unicode U+2200 (category Sm: Symbol, math)

It is about the validity.

yea, I agree here that char is not length dependent. I made my suggestion too quickly and more as a general idea.

Maybe something like invalid character - contains multiple characters or something like that would be more appropriate.

The main point I want to stress is now that I've gone through this, I'll know what ERROR: syntax: Invalid character literal means when I run into it in the future, but the amount of time and energy it took to figure this out the first time could have been minimized with a more informative error message. And, as more people move to the language with, I'm sure others will fall into this same hole.

On a maybe related note. Did you know that julia never finishes evaluating this char ->'\'. I know it's. used as escaping but this may be unintended behavior. If so, I'll create a separate issue for it.

'\' is just incomplete input, since we haven't seen the closing ' yet. It behaves just like f( or '.

For the original issue, it would be easy to give a more specific message like "character literal contains multiple characters".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Keno picture Keno  ·  3Comments

manor picture manor  ·  3Comments

iamed2 picture iamed2  ·  3Comments

TotalVerb picture TotalVerb  ·  3Comments

arshpreetsingh picture arshpreetsingh  ·  3Comments