Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed error message for end-of-line colons #34756

Merged
merged 1 commit into from
Apr 13, 2020

Conversation

naveenarun
Copy link
Contributor

I'm a Python user who's just starting to learn Julia, and I was playing around with function definitions and wrote a function with the following syntax:

function test_function(inputs):
    ...
end

I then got the following error message:

ERROR: syntax: space not allowed after ":" used for quoting

I was confused because I wasn't aware yet that colons were used for quoting, and ended up trying to search for a space character in my code (after all, I had a newline - not a space - after the colon). Wasted quite a bit of time trying to fix it.

This PR just changes the error message to the following, meant to be nudge Python users in the right direction:

ERROR: syntax: space not allowed after ":" used for quoting. (Did you put ":" after a function/if/while/for statement?)

@yuyichao
Copy link
Contributor

As recently shown, error message suggesting the wrong cause can be very confusing for people that hit it for other reasons. Having guess work in the error message is fine but I don't believe having EOL : after begining of block is the most likely cause of this error so this new message should only be printed in more specific cases.

@naveenarun
Copy link
Contributor Author

naveenarun commented Feb 13, 2020

I did a google search for exact matches of the error message and got the following breakdown for 19 results:

Based on this breakdown, I removed the parts of the error message talking about if/while/for statements but kept the part re. function definitions. I think that this change, at least for the time being, would not majorly confuse people debugging ternary operator errors.

@yuyichao
Copy link
Contributor

While it's nice that you did the research by searching for the error message, the result, unfortunately doesn't mean anything. It's by construction biased against people whose problem is solved by the current error message. FWIW, I think mentioning while/if/for is fine, removing them makes it worse.

@naveenarun
Copy link
Contributor Author

You're right. I'll try to change this so that the message only comes up in more specific cases.

@naveenarun naveenarun closed this Feb 14, 2020
@yuyichao
Copy link
Contributor

Fwiw, I don't think you need to be too specific. Just end of line should be good enough and from a quick look at the code that should not be hard....

@naveenarun naveenarun reopened this Feb 14, 2020
@naveenarun
Copy link
Contributor Author

Alright, I changed the error message from

ERROR: syntax: space not allowed after ":" used for quoting

to

ERROR: syntax: space or newline not allowed after ":" used for quoting

in the two places where it's relevant.

@yuyichao
Copy link
Contributor

I do think this is a strict improvement. You could probably also split the conditon and give your python related error message if the first condition is true.

@@ -1220,7 +1220,7 @@
(take-token s)
(if (or (eqv? (peek-token s) #\newline)
(ts:space? s)) ;; uses side effect of previous peek-token
(error "space not allowed after \":\" used for quoting"))
(error "space or newline not allowed after \":\" used for quoting"))
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(error "space or newline not allowed after \":\" used for quoting"))
(cond ((eqv? (peek-token s) #\newline)
(error "newline not allowed after \":\" used for quoting"))
((ts:space? s) ;; uses side effect of previous peek-token
(error "whitespace not allowed after \":\" used for quoting"))
((else

The expression
```
function test_function(inputs):
    ...
end
```
currently gives the following syntax error
```
ERROR: syntax: space not allowed after ":" used for quoting
```
This can be a bit confusing for users who do not know
about quoting and do not intend it to be used as such.
Since this kind of mistake is common for users coming from
Python, try to give an improved error message.
@Keno Keno force-pushed the improve_colon_error_message branch from 119be8c to 41c4030 Compare April 11, 2020 02:14
@Keno
Copy link
Member

Keno commented Apr 11, 2020

Rebased and applied @vtjnash's suggestion to both instances.

@Keno Keno merged commit 98ee67c into JuliaLang:master Apr 13, 2020
ztultrebor pushed a commit to ztultrebor/julia that referenced this pull request Apr 17, 2020
…Lang#34756)

The expression
```
function test_function(inputs):
    ...
end
```
currently gives the following syntax error
```
ERROR: syntax: space not allowed after ":" used for quoting
```
This can be a bit confusing for users who do not know
about quoting and do not intend it to be used as such.
Since this kind of mistake is common for users coming from
Python, try to give an improved error message.
staticfloat pushed a commit that referenced this pull request Apr 21, 2020
The expression
```
function test_function(inputs):
    ...
end
```
currently gives the following syntax error
```
ERROR: syntax: space not allowed after ":" used for quoting
```
This can be a bit confusing for users who do not know
about quoting and do not intend it to be used as such.
Since this kind of mistake is common for users coming from
Python, try to give an improved error message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants