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

Fix `==` and `!=` when comparing signed vs unsigned integers #6689

Merged
merged 1 commit into from Sep 10, 2018

Conversation

Projects
None yet
6 participants
@asterite
Contributor

asterite commented Sep 9, 2018

Fixes #571

@bcardiff

This comment has been minimized.

Member

bcardiff commented Sep 9, 2018

Why closing it? I was up to send the approval.

@asterite asterite reopened this Sep 10, 2018

@asterite

This comment has been minimized.

Contributor

asterite commented Sep 10, 2018

@bcardiff Because it stucks at one spec, probably this broke something that depended on that equality. I'll reopen and investigate why it's failing, and try to fix that.

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch from 5ffd993 to fa524cc Sep 10, 2018

@asterite

This comment has been minimized.

Contributor

asterite commented Sep 10, 2018

Hopefully fixed. The iconv call returns size_t and an error is signaled as (size_t)(-1), so before this PR comparing an uint with -1 would work just fine, now it doesn't. Fixed by using LibC::SizeT::MAX instead of -1, but now I'm also marking this PR as a breaking change... what's worse is that this is a silent breaking change, but it might be better to do this now and not later.

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch from fa524cc to d550776 Sep 10, 2018

@@ -161,6 +161,26 @@ class Crystal::CodeGenVisitor
end
end
# The below methods (lt, lt2, gt, gte, eq, ne) perform

This comment has been minimized.

@RX14

RX14 Sep 10, 2018

Member

s/lt2/lte/

Bit of a nitpick but it genuinely confused me for 30s

This comment has been minimized.

@asterite

asterite Sep 10, 2018

Contributor

Good catch. Fixed!

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch from d550776 to 6ffffd0 Sep 10, 2018

@RX14

This comment has been minimized.

Member

RX14 commented Sep 10, 2018

Amazing, you corrected the typo before I even had time to finish reading the whole diff!

@RX14

RX14 approved these changes Sep 10, 2018

@RX14 RX14 added this to the 0.27.0 milestone Sep 10, 2018

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch 2 times, most recently from 96426d8 to cc2ab58 Sep 10, 2018

@asterite

This comment has been minimized.

Contributor

asterite commented Sep 10, 2018

I keep adding fixes. This time, getting runtime integer values from LLVM returned UInt64 and we sometimes compared that with -1, so now it fails. I fixed it by making that used method to return Int32, while also allowing to get the values as Int64 and UInt64, which is what LLVM provides (but in the tests we don't use such big values so it's always safe to use Int32).

@RX14

This comment has been minimized.

Member

RX14 commented Sep 10, 2018

CI still failing :C

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch from cc2ab58 to 97271b9 Sep 10, 2018

@asterite

This comment has been minimized.

Contributor

asterite commented Sep 10, 2018

CI passed 🎉

@@ -537,6 +537,18 @@ describe "Int" do
end
end
{% if compare_versions(Crystal::VERSION, "2.6.1") > 0 %}

This comment has been minimized.

@luislavena

luislavena Sep 10, 2018

Contributor

@asterite is this version correct? Shouldn't be 0.26.1 instead?

This comment has been minimized.

@asterite

asterite Sep 10, 2018

Contributor

Oops! Fixed :-)

@asterite asterite force-pushed the asterite:bug/571-signed-unsigned-comparison branch from 97271b9 to 086f372 Sep 10, 2018

(x == y).should be_false
(y == x).should be_false
(x != y).should be_true
(y != x).should be_true

This comment has been minimized.

@j8r

j8r Sep 10, 2018

Contributor

Wouldn't it be better to use should eq and should_not eq expectations to have a report of variables if it fails?

This comment has been minimized.

@asterite

asterite Sep 10, 2018

Contributor

I don't know, here we are testing those operators and I wouldn't like to hide them behind a spec matcher.

This comment has been minimized.

@RX14

RX14 Sep 10, 2018

Member

this is better as-is

@RX14

RX14 approved these changes Sep 10, 2018

@RX14 RX14 merged commit d8a1601 into crystal-lang:master Sep 10, 2018

4 checks passed

ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@NoICE

This comment has been minimized.

NoICE commented Sep 11, 2018

You guys are awesome. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment