Skip to content

Instantly share code, notes, and snippets.

@Papierkorb
Created May 24, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Papierkorb/299df2557e6abdd2e3cc1dbec0fe14d4 to your computer and use it in GitHub Desktop.
Save Papierkorb/299df2557e6abdd2e3cc1dbec0fe14d4 to your computer and use it in GitHub Desktop.
{% 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