evhub / coconut

Simple, elegant, Pythonic functional programming.
http://coconut-lang.org
Apache License 2.0
4.04k stars 120 forks source link

Coefficient syntax error message is too specific #827

Closed kg583 closed 6 months ago

kg583 commented 6 months ago

Coefficient syntax errors raise the following message:

TypeError: implicit function application and coefficient syntax only supported for Callable, int, float, complex, and numpy objects

However, this message is too specific, as coefficient syntax can be applied to any variable, regardless of type:

x = [1, 2, 3]
print(2x)

x = "foo"
print(2x)

It even parses fine the other way, with type checks distinguishing application and multiplication just fine:

x = 1
print(x 2)

x = bytes
print(x 2)

All of this is to say that the error message could be improved to indicate that things are a bit more smart and relaxed than they seem. I'm not sure of a particular replacement yet, though, because the message does accurately relay the situation for literals.

evhub commented 6 months ago

Well, it's a TypeError, not a SyntaxError—it works for variables, but only variables that point to objects of the right type. Documentation could potentially be improved here, though.

kg583 commented 6 months ago

it works for variables, but only variables that point to objects of the right type.

Except that's just not true, as my examples show, unless the message refers to the coefficient type (which is then still unclear).

evhub commented 6 months ago

Ah, yes, I see the confusion. It is referring to the first object in the expression (the coefficient in your examples).