-
-
Save Papierkorb/299df2557e6abdd2e3cc1dbec0fe14d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if true %} | |
# Tuple as part of the alias breaks things: | |
alias Type = String | Hash(Type, Type) | Array(Type) | Tuple(Type, Type) | |
{% else %} | |
# This works fine: No Tuple() part! | |
# alias Type = String | Hash(Type, Type) | Array(Type) | |
alias Type = String | |
{% end %} | |
class Val | |
getter raw : Type | |
def initialize(@raw) | |
end | |
def first | |
case object = @raw | |
when Enumerable | |
object.first | |
when String | |
object[0, 1] | |
end | |
end | |
end | |
# This one works just fine. | |
pp Val.new("foo").first | |
# #first will return random memory as String | |
pp Val.new({ "foo".as(Type), "foo".as(Type) }).first | |
# And this will outright crash the compiler | |
# pp Val.new({"foo".as(Type) => "bar".as(Type)}).first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment