diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 6a6461d36..24565e300 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -305,6 +305,10 @@ trait Types requires SymbolTable { */ def matches(that: Type): boolean = matchesType(this, that, !phase.erasedTypes) + /** Same as matches, except that non-method types are always assumed to match. + */ + def looselyMatches(that: Type): boolean = matchesType(this, that, true) + /** The shortest sorted upwards closed array of types that contains * this type as first element. * @@ -447,7 +451,7 @@ trait Types requires SymbolTable { member.owner != sym.owner && !sym.hasFlag(PRIVATE) && { if (self eq null) self = this.narrow; - matchesType(self.memberType(member), self.memberType(sym), !phase.erasedTypes) + (self.memberType(member) matches self.memberType(sym)) })) { members = newScope(List(member, sym)) } @@ -458,7 +462,7 @@ trait Types requires SymbolTable { prevEntry.sym.owner != sym.owner && !sym.hasFlag(PRIVATE) && { if (self eq null) self = this.narrow; - matchesType(self.memberType(prevEntry.sym), self.memberType(sym), !phase.erasedTypes) + (self.memberType(prevEntry.sym) matches self.memberType(sym)) })) { prevEntry = members lookupNextEntry prevEntry } diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 38e0404d5..bea50aa71 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -484,6 +484,18 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { copy.Match(tree1, selector, cases map adaptCase) case Try(block, catches, finalizer) => copy.Try(tree1, adaptBranch(block), catches map adaptCase, finalizer) + case Ident(_) | Select(_, _) => + if (tree1.symbol hasFlag OVERLOADED) { + val first = tree1.symbol.alternatives.head + val sym1 = tree1.symbol.filter { + alt => alt == first || !(first.tpe looselyMatches alt.tpe) + } + if (tree.symbol ne sym1) { + tree1.symbol = sym1 + tree1.tpe = sym1.tpe + } + } + tree1 case _ => tree1 }