-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Error when nested array/hash is used on inheritance #10133
Comments
Combinations
work well. It seems that only fails when |
This is very well a bug, but inheriting from |
Yeah I just use an uninherited class with 2D |
This happens to any nested generic, not just class Foo(T)
end
class Bar(T)
def initialize
@buffer = Foo(T).new
end
end
class Baz < Bar(Bar(Int32))
end
Baz.new
# Error: instance variable '@buffer' of Bar(Bar(Int32)) must be Foo(Bar(Int32)), not Foo(Bar(Int32)) |
Closing as duplicate of #2665 |
The above class A(T1)
end
class B(T2)
end
class C(T3)
@entries = A(B(T3)).new
end
class D < C(C(Int32))
end
D.new # Error: instance variable '@entries' of C(C(Int32)) must be A(B(C(Int32))), not A(B(C(Int32))) |
The array example is not really fixed: class Foo(T)
end
class Bar(T)
def initialize
@buffer = Foo(T).new
end
end
class Baz < Bar(Bar(Int32))
end
typeof(Baz.new.@buffer) # => (Foo(Bar(Int32)) | Foo(Bar(Int32))) This seemingly reducible union is actually So this is related to #10302 (comment). Regardless of whether virtual types will stay, there should never be a need for generic type arguments to be virtual. |
Another snippet taken from the forum: class Item(V)
end
class Foo(T)
end
class Bar(V) < Foo(Item(V))
@foo = uninitialized Item(V)
def foo(value : V, name = nil)
@foo = Item(V).new # Error: instance variable '@foo' of Bar(Tuple(Foo(String))) must be Item(Tuple(Foo(String))), not Item(Tuple(Foo(String)))
end
end
x = Bar(Tuple(Foo(String))).new
x.foo({Foo(String).new}) |
This issue has been mentioned on Crystal Forum. There might be relevant details there: |
(carc)
This produces an error:
Error: instance variable '@buffer' of Array(Array(UInt32)) must be Pointer(Array(UInt32)), not Pointer(Array(UInt32))
With 1-dimensional array it works:
(carc)
Same for Hash (reduced as much as possible):
(carc)
Error: instance variable '@entries' of Hash(UInt32, Hash(UInt32, UInt32)) must be Pointer(Hash::Entry(UInt32, Hash(UInt32, UInt32))), not Pointer(Hash::Entry(UInt32, Hash(UInt32, UInt32)))
Tested against master too at:
Crystal 1.0.0-dev [935476e] (2020-12-18)
.The text was updated successfully, but these errors were encountered: