Bad codegen when comparing isNil results #4975

Closed
endragor opened this Issue Oct 31, 2016 · 1 comment

Projects

None yet

2 participants

@endragor
Contributor

Sample:

var s1, s2: string
s2 = ""
let eq = (s1.isNil) == (s2.isNil)
echo eq # true!!

During codegen, the parens are omitted and so the operation order becomes incorrect. nim cpp actually errors out, because C++ is more strict:

sample.cpp:318:50: error: comparison between pointer and integer ('int' and 'NimStringDesc *')
        eq_95013_2492582993 = (s1_95009_2492582993 == 0 == s2_95010_2492582993 == 0);
                               ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~

Nim v0.15.2

@scroot
scroot commented Nov 1, 2016 edited

Nim: 0.15.2
Copyright (c) 2006-2016 by Andreas Rumpf
git hash: 5cb5036
active boot switches: -d:release

Windows 10 build 14931

var s1,s2:string
s2=""
echo "s1=", s1.isNil
echo "s2=",s2.isNil
let eq = (s1.isNil) == (s2.isNil)

echo eq

s1=true
s2=false
true
重现

@Araq Araq added a commit that closed this issue Nov 7, 2016
@Araq Araq fixes #4975 24c47dd
@Araq Araq closed this in 24c47dd Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment