Skip to content

Commit e4a684f

Browse files
authored
Merge pull request scala#6150 from milessabin/topic/singleton-type-patterns
When checking for a non-empty type intersection don't treat Singleton as final
2 parents c7de0eb + 263829f commit e4a684f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/reflect/scala/reflect/internal/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
10171017

10181018
/** Is this symbol effectively final? I.e, it cannot be overridden */
10191019
final def isEffectivelyFinal: Boolean = (
1020-
(this hasFlag FINAL | PACKAGE)
1020+
((this hasFlag FINAL | PACKAGE) && this != SingletonClass)
10211021
|| isModuleOrModuleClass && (isTopLevel || !settings.overrideObjects)
10221022
|| isTerm && (isPrivate || isLocalToBlock || (hasAllFlags(notPRIVATE | METHOD) && !hasFlag(DEFERRED)))
10231023
|| isClass && originalOwner.isTerm && children.isEmpty // we track known subclasses of term-owned classes, use that infer finality

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,12 +4133,13 @@ trait Types
41334133
throw new MatchError((tp1, tp2))
41344134
}
41354135

4136-
def check(tp1: Type, tp2: Type) = (
4137-
if (tp1.typeSymbol.isClass && tp1.typeSymbol.hasFlag(FINAL))
4138-
tp1 <:< tp2 || isNumericValueClass(tp1.typeSymbol) && isNumericValueClass(tp2.typeSymbol)
4136+
def check(tp1: Type, tp2: Type) = {
4137+
val sym1 = tp1.typeSymbol
4138+
if (sym1.isClass && sym1.hasFlag(FINAL) && sym1 != SingletonClass)
4139+
tp1 <:< tp2 || isNumericValueClass(sym1) && isNumericValueClass(tp2.typeSymbol)
41394140
else tp1.baseClasses forall (bc =>
41404141
tp2.baseTypeIndex(bc) < 0 || isConsistent(tp1.baseType(bc), tp2.baseType(bc)))
4141-
)
4142+
}
41424143

41434144
check(tp1, tp2) && check(tp2, tp1)
41444145
}

test/files/pos/t10569.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
object Foo
3+
Tuple1[Foo.type](Foo) match {
4+
case Tuple1(foo: Singleton) => foo
5+
}
6+
}

0 commit comments

Comments
 (0)