Skip to content

Commit 83735d2

Browse files
Merge pull request #4519 from dotty-staging/fix-4496-part1
Selectable: catch correct exception when the field isn't found
2 parents 2136fc1 + b077695 commit 83735d2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

library/src/scala/reflect/Selectable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Selectable(val receiver: Any) extends AnyVal with scala.Selectable {
88
fld.get(receiver)
99
}
1010
catch {
11-
case ex: NoSuchFieldError =>
11+
case ex: NoSuchFieldException =>
1212
selectDynamicMethod(name).asInstanceOf[() => Any]()
1313
}
1414
}

tests/run/i4496a.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.reflect.Selectable.reflectiveSelectable
2+
class Foo1 { val a: Int = 10 }
3+
class Foo2 { def a: Int = 10 }
4+
class Foo3 { var a: Int = 10 }
5+
object Test {
6+
def main(args: Array[String]): Unit = {
7+
assert((new Foo1 : {val a: Int}).a == 10)
8+
assert((new Foo2 : {val a: Int}).a == 10)
9+
assert((new Foo3 : {val a: Int}).a == 10)
10+
}
11+
}

0 commit comments

Comments
 (0)