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

var = uninitialized T returns Nil instead of type T #3641

Closed
bcardiff opened this issue Dec 5, 2016 · 1 comment
Closed

var = uninitialized T returns Nil instead of type T #3641

bcardiff opened this issue Dec 5, 2016 · 1 comment

Comments

@bcardiff
Copy link
Member

bcardiff commented Dec 5, 2016

The following code is not working as expected:

g = h = uninitialized Int32
puts typeof(h) # => Int32
puts typeof(g) # => Nil

It should be

g = h = uninitialized Int32
puts typeof(h) # => Int32
puts typeof(g) # => Int32

I reach this reducing from

a = if rand() > 0.5
  1
else
  b = uninitialized Int32
  b
end
typeof(a) # => Int32

c = if rand() > 0.5
  1
else
  d = uninitialized Int32
end
typeof(c) # => Int32 | Nil

It seems var = uninitialized T is not returning the garbage value of type T.

crystal: 0.20.0

@asterite
Copy link
Member

asterite commented Dec 5, 2016

Yes, uninitialized doesn't return anything, it's more like a statement than an expression. Doing a = b = uninitialized Int32 will not mark a as uninitialized. I'm not sure I'd like to change this.

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

No branches or pull requests

2 participants