Match with autocast should work on primitive types #760

Closed
nddrylliog opened this Issue Jan 3, 2014 · 3 comments

Projects

None yet

2 participants

@nddrylliog
Member

Example:

a: Int
a = 12
b := match (a) {
        case str: String => "String"
        case num: Int => "Int"
        case => "unknown"
}
"b: %s" printfln(b)

Currently that crashes, as 'a' is cast to an object for some reason. Note that we could be a smart compiler and just yank the rest of the cases - actually it's not very useful code, but there's no reason why it should crash.

@fasterthanlime
Collaborator

Ok so here's a shorter one - apparently covers still inherit from object, which has instanceOf, so this crashes as well:

v := 12 instanceOf?(Object)
"12 is object? #{v}" println()
@fasterthanlime
Collaborator

But here's the thing - I kinda think instanceOf should work even on covers, because it's a bit special, like an operator (like new) - that would fix the match case (ha!).

@fasterthanlime
Collaborator

Interesting side problem, while fixing, I discovered that

12 class inheritsFrom?(Object)

Evaluates to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment