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

Generic type parameter in class level initialization #4291

Closed
jbomanson opened this issue Apr 14, 2017 · 0 comments
Closed

Generic type parameter in class level initialization #4291

jbomanson opened this issue Apr 14, 2017 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler

Comments

@jbomanson
Copy link

jbomanson commented Apr 14, 2017

The code

class AA(T)
  @value = T.new(0)
end

brings up the following error

Error in class_level_generic_new.cr:2: undefined method 'new' for T:Class

  @value = T.new(0)

However, I think it should work identically to the following code, which does compile:

class AA(T)
  def initialize
    @value = T.new(0)
  end
end

With this, you can create objects like AA(Int32).new and AA(Int64).new.

The first variant used to work as well with crystal 0.18.7.
It appears to have stopped working from version 0.19.0 onward, based on testing in play.crystal-lang.org.
My crystal --version is Crystal 0.21.1 [3c6c75e] (2017-03-06) LLVM 3.5.0 and OS is ubuntu 16.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler
Projects
None yet
Development

No branches or pull requests

2 participants