-
-
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
Splat type vars in inheritance #3649
Comments
Probably both snippets are just compiler bugs, I never imagined a use case for that (splats in types are not complete yet in the compiler) What are you trying to do? :-) |
@asterite if this is actually a compiler bug, I can send a PR for fixing this. |
I don't think In any case, this is super minor, I can't think of any use case for that code. |
If there are abstract defs in abstract class Bar(T, T2)
abstract def get(key : T) : T2
abstract def set(key : T, value : T2)
end Then it is pretty much impossible to implement them in class Foo(*T) < Bar(*T)
def get(key : K) forall K
{% if K <= T[0] %} # bad, obscures overload resolution
{% end %}
end
def get(key : T[0]) : T[1] # incorrect, these form `StaticArray`s
end
def get(key : typeof(0.unsafe_as(T)[0])) : typeof(0.unsafe_as(T)[1]) # `typeof` not allowed here
end
def set(*args : *T) # technically allowed, but also bad
end
end This shortcoming is huge enough that I'm inclined to make both snippets compile-time errors; that is, a splat expansion must correspond to a splat parameter in the included/inherited type. If it's possible to access members of a type var splat in these contexts then we could revisit this feature. However, if class Bar(*T)
def self.f
T
end
end
class Foo(*U) < Bar(*U)
end
Foo(Int32, String).f # expected: Tuple(Int32, String)
# got: Tuple(*U) This part is covered by #10232. |
My bad, abstract class Bar(T, T2)
abstract def get(key : T) : T2
abstract def set(key : T, value : T2)
end
class Foo(*T3) < Bar(*T3)
def get(key : T) : T2
raise ""
end
def set(key : T, value : T2)
end
end |
Submitting bugs
Thank you, too 😄
Code 1:
Result:
Code 2:
Result:
Question
In code 1, if splat type var is not support in crystal, this should be syntax error.
In code 2, if splat type var is supported, what is the rule of the splat type var?
Crystal version
The text was updated successfully, but these errors were encountered: