Skip to content

More tests for switches #5071

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

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ object Main {
}

// has a guard, but since SI-5830 that's ok
def succ_guard(c: Char) = (c: @switch) match {
case 'A' | 'B' | 'C' => true
case x if x == 'A' => true
case _ => false
}
// PENDING: #5070
// def succ_guard(c: Char) = (c: @switch) match {
// case 'A' | 'B' | 'C' => true
// case x if x == 'A' => true
// case _ => false
// }

// throwing in @unchecked on the next two to make sure
// multiple annotations are processed correctly

// thinks a val in an object is constant... so naive
def fail2(c: Char) = (c: @switch @unchecked) match {
def fail1(c: Char) = (c: @switch @unchecked) match { // error: Could not emit switch for @switch annotated match
case 'A' => true
case Other.C1 => true
case _ => false
}

// more naivete
def fail3(c: Char) = (c: @unchecked @switch) match {
def fail2(c: Char) = (c: @unchecked @switch) match { // error: Could not emit switch for @switch annotated match
case 'A' => true
case Other.C3 => true
case _ => false
Expand All @@ -63,4 +64,14 @@ object Main {
case 5|6|7|8 => 100
case _ => -1
}

def fail3(x: Any) = (x: @switch) match { // error: Could not emit switch for @switch annotated match
case 1 | 2 | 3 => true
case _ => false
}

def fail4(x: AnyVal) = (x: @switch) match { // error: Could not emit switch for @switch annotated match
case 1 | 2 | 3 => true
case _ => false
}
}
10 changes: 10 additions & 0 deletions tests/pos-special/fatal-warnings/switches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class Test {
case 14 => 4
case _ => 5
}

def test4(x: Byte): Boolean = (x: @switch) match {
case 1 | 2 | 3 => true
case _ => false
}

def test5(x: Short): Boolean = (x: @switch) match {
case 1 | 2 | 3 => true
case _ => false
}
}

object Test {
Expand Down