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

`str &= data` doesn't behave as `str = str & data`. #10963

Closed
kayabaNerve opened this issue Apr 4, 2019 · 2 comments

Comments

Projects
None yet
5 participants
@kayabaNerve
Copy link
Collaborator

commented Apr 4, 2019

If a string and an int are combined via &, a compilation error occurs. When combined via &=, the int is converted to a string via $ and the code compiles. This error doesn't occur in Nimscript, and is localized to Nim.

var
    a: string = "abc"
    b: int = 5
a &= b
echo a

Current Output

abc5

Expected Output

Compilation Error of Error: type mismatch: got <string, int>

Tested on 0.19.0, 0.19.4, and devel (compiled as this issue was written). All three had Nimscript (tested via nim secret) throw an error, but Nim compile.

@PMunch

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

According to Araq on IRC this is caused by an add proc that takes a string and an int, which I assume is this one: https://nim-lang.org/0.19.2/system.html#add%2Cstring%2Cint64

EDIT: And the rewrite seems to happen here: https://github.com/nim-lang/Nim/blob/master/lib/system.nim#L3822 commenting out that and adding a procedure that takes string + char works fine for compiling Nim itself. Not sure if any library out there uses this though..

@mratsim

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2019

I think a & overload for string, int should be in sugar.nim or lenientops.nim, same thing for &=.

Tagging RFC as it's more of a system.nim / standard library design question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.