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
Stack overflow during compilation #7125
Comments
Right now you can't store things with a Class type. That's why it probably crashes. |
I dag a bit more on the problem: since if I create a literal hash with classes as keys it compiles, I run this simple cone on the online Crystal compiler dummy = {String => 1}
p typeof(dummy) ant it returned
This can be a solution to my problem. Stepping back, the code I put in the first comment makes crystal running in stack overflow during compilation without raising any specific exception... |
Closed by mistake.. |
Actually, I'm curious why is A program entirely of
fails with In any case @max-codeware - do you actually need this for user types, or an unknown number of types? Or just primitives / some finite collection of types? I think an explicit Union of # Alias for ease of reference in multiple locations, if needed:
alias Any = String.class | Int32.class | Bool.class
hash = Hash(Any, Int32).new
hash[String] = 1
hash[Int32] = 2
hash[Bool] = 3
p typeof(hash) # Hash(Bool.class | Int32.class | String.class, Int32)
p hash # {String => 1, Int32 => 2, Bool => 3} Maybe a macro could be applied to make this flexible, but I don't know enough about your use case at a glance. |
@z64 I was curious too: I just tried this script on the online compiler and I report it here: module A
@@var = uninitialized Hash(Class,Int32)
def self.var
@@var = {String => 1}
end
end
p A.var And it gave me back this error: About my case, here I have a Hash that has many classes as key. I could , of course, use the top level class |
Can it repro still? I seem to get this now: |
I'm facing a stack overflow during Semantic (main). I think this problem has something in common with #2604 (this issue made me understand what the problem was).
The line that's causing the compiler crash is this
LcClass
is a defined type (not part of the problem).If I change that line with
The program compiles with no problems, but I must tell the compiler the keys of the hash will be classes and not strings.
I tried to reproduce this with a smaller code using the online compiler, but with no success..
How can I solve this issue?
The text was updated successfully, but these errors were encountered: