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

inferred literals and integer-const expressions aren't overflow checked #4220

Closed
graydon opened this issue Dec 19, 2012 · 11 comments
Closed
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@graydon
Copy link
Contributor

graydon commented Dec 19, 2012

The most egregious example is: let x:u8 = 10_000; which compiles without complaint. But more generally, if we're going to make a promise to constant-fold the integer-constant grammar, we might well consider overflow checks on all those arithmetic nodes. Opinions?

@graydon
Copy link
Contributor Author

graydon commented Dec 19, 2012

cc @lkuper

@nikomatsakis
Copy link
Contributor

My suggestion for how to deal with this:

Leave type check as it is. Instead, insert a lint check that examines all literals (or perhaps constant expressions) and checks whether they fit into the type that was inferred for them.

@sophiebits
Copy link
Contributor

(Mostly a dupe of #3084.)

@x--
Copy link

x-- commented Jan 8, 2013

I have written this patch x--@e9aab10 that basically add checks for assign and assign_op expressions.
@graydon recommended that these checks would be more useful in middle::const_eval so, gonna try to put the checks there.

@nikomatsakis
Copy link
Contributor

What I had envisioned was similar to your patch @x-- except that I thought we'd just visit integer literals and check the type that was assigned to them, rather than putting the checks on assignments. However, @graydon's suggestion sounds like a superset of this check.

@nikomatsakis
Copy link
Contributor

Not critical for 0.6; de-milestoning

@catamorphism
Copy link
Contributor

Nominating for milestone 2 (backwards-compatible).

@brson
Copy link
Contributor

brson commented Aug 1, 2013

cc #5551

@graydon
Copy link
Contributor Author

graydon commented Aug 1, 2013

sub-bug of #5551

@graydon
Copy link
Contributor Author

graydon commented Aug 1, 2013

accepted for well-defined milestone

@emberian
Copy link
Member

@fhahn you are super awesome for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

7 participants