Skip to content

Selectable: catch correct exception when the field isn't found #4519

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
May 12, 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
2 changes: 1 addition & 1 deletion library/src/scala/reflect/Selectable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Selectable(val receiver: Any) extends AnyVal with scala.Selectable {
fld.get(receiver)
}
catch {
case ex: NoSuchFieldError =>
case ex: NoSuchFieldException =>
selectDynamicMethod(name).asInstanceOf[() => Any]()
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/run/i4496a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.reflect.Selectable.reflectiveSelectable
class Foo1 { val a: Int = 10 }
class Foo2 { def a: Int = 10 }
class Foo3 { var a: Int = 10 }
object Test {
def main(args: Array[String]): Unit = {
assert((new Foo1 : {val a: Int}).a == 10)
assert((new Foo2 : {val a: Int}).a == 10)
assert((new Foo3 : {val a: Int}).a == 10)
}
}