From b941551529e40fc7d71cf25e1ad904ab7badd14c Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 22 May 2013 15:51:18 +0200 Subject: SI-6138 Centralize and refine detection of `getClass` calls `getClass` is special cased in the compiler; this is described in in the comments on `Definitions.Any_getClass`. Part of this happens in `Typer#stabilize`. This was trying to determine if an Ident or Select node was a call to `getClass` by merits of the name of the tree's symbol and by checking that the its type (if it was a MethodType or PolyType) had no parameters in the primary parameter list. Overloaded user defined `getClass` methods confused this check. In the enclosed test case, the tree `definitions.this.getClass` had an `OverloadedType`, and such types always report an empty list of `params`. This commit: - changes `stabilize` to use `isGetClass`, rather than the homebrew check - changes `isGetClass` to consider a `Set[Symbol]` containing all `getClass` variants. This moves some similar code from `Erasure` to `Definitions` - keeps a fast negative path in `isGetClass` based on the symbol's name --- test/files/neg/t6138.check | 7 +++++++ test/files/neg/t6138.scala | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 test/files/neg/t6138.check create mode 100644 test/files/neg/t6138.scala (limited to 'test/files/neg') diff --git a/test/files/neg/t6138.check b/test/files/neg/t6138.check new file mode 100644 index 0000000000..8fd9978248 --- /dev/null +++ b/test/files/neg/t6138.check @@ -0,0 +1,7 @@ +t6138.scala:4: error: ambiguous reference to overloaded definition, +both method getClass in object definitions of type (s: Int)Any +and method getClass in object definitions of type (s: String)Any +match argument types (Nothing) + getClass(???): String + ^ +one error found diff --git a/test/files/neg/t6138.scala b/test/files/neg/t6138.scala new file mode 100644 index 0000000000..2f45a46b1c --- /dev/null +++ b/test/files/neg/t6138.scala @@ -0,0 +1,5 @@ +object definitions { + def getClass(s: String): Any = ??? + def getClass(s: Int): Any = ??? + getClass(???): String +} -- cgit v1.2.3