Skip to content

Commit 386a602

Browse files
Backport "Fix isEffectivelySingleton" to LTS (#21128)
Backports #20486 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 9d44884 + a88da44 commit 386a602

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,12 @@ object Types extends TypeUtils {
327327
def isSingleton(using Context): Boolean = dealias.isInstanceOf[SingletonType]
328328

329329
/** Is this type a (possibly aliased) singleton type or a type proxy
330-
* or Or/And type known to be a singleton type?
330+
* or an AndType where one operand is effectively a singleton?
331331
*/
332332
def isEffectivelySingleton(using Context): Boolean = dealias match
333333
case tp: SingletonType => true
334334
case tp: TypeProxy => tp.superType.isEffectivelySingleton
335335
case AndType(tpL, tpR) => tpL.isEffectivelySingleton || tpR.isEffectivelySingleton
336-
case OrType(tpL, tpR) => tpL.isEffectivelySingleton && tpR.isEffectivelySingleton
337336
case _ => false
338337

339338
/** Is this type of kind `AnyKind`? */

tests/neg/i20474.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class A
2+
class B extends A
3+
4+
def f(a: A, c: A) =
5+
val b1: a.type = a
6+
val b2: a.type & B = a.asInstanceOf[a.type & B]
7+
val b3: c.type & A = c
8+
val b4: a.type | c.type = c
9+
10+
val d1: b1.type = a
11+
val d2: b2.type = a // ok
12+
val d3: b3.type = a // error
13+
val d4: b4.type = a // error

0 commit comments

Comments
 (0)