Skip to content

Commit 5a86c1f

Browse files
authored
Merge pull request #8062 from dotty-staging/fix-#8058
Fix #8058: Fix `isStableMember` test
2 parents 7282a9b + bb009bf commit 5a86c1f

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
442442

443443
/** The purity level of this reference.
444444
* @return
445-
* PurePath if reference is (nonlazy and stable) or to a parameterized function
445+
* PurePath if reference is (nonlazy and stable)
446+
* or to a parameterized function
447+
* or its type is a constant type
446448
* IdempotentPath if reference is lazy and stable
447449
* Impure otherwise
448450
* @DarkDimius: need to make sure that lazy accessor methods have Lazy and Stable
@@ -452,6 +454,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
452454
val sym = tree.symbol
453455
if (!tree.hasType) Impure
454456
else if (!tree.tpe.widen.isParameterless || sym.isEffectivelyErased) PurePath
457+
else if tree.tpe.isInstanceOf[ConstantType] then PurePath
455458
else if (!sym.isStableMember) Impure
456459
else if (sym.is(Module))
457460
if (sym.moduleClass.isNoInitsClass) PurePath else IdempotentPath

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ object SymDenotations {
727727
*/
728728
final def isStableMember(implicit ctx: Context): Boolean = {
729729
def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType]
730-
isType || is(StableRealizable) || !isUnstableValue
730+
isType || is(StableRealizable) || exists && !isUnstableValue
731731
}
732732

733733
/** Is this a denotation of a class that does not have - either direct or inherited -

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ object Types {
10821082
/** Widen type if it is unstable (i.e. an ExprType, or TermRef to unstable symbol */
10831083
final def widenIfUnstable(implicit ctx: Context): Type = stripTypeVar match {
10841084
case tp: ExprType => tp.resultType.widenIfUnstable
1085-
case tp: TermRef if !tp.symbol.isStableMember => tp.underlying.widenIfUnstable
1085+
case tp: TermRef if tp.symbol.exists && !tp.symbol.isStableMember => tp.underlying.widenIfUnstable
10861086
case _ => this
10871087
}
10881088

tests/run/i8058.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extension on (x: Array[Char]):
2+
inline def swap(i: Int, j: Int) : Unit =
3+
val v = x(i)
4+
x(i) = x(j)
5+
x(j) = v
6+
7+
@main def Test =
8+
val a = Array('A','B')
9+
a.swap(0, 1)
10+
assert(a.toList == List('B', 'A'))

0 commit comments

Comments
 (0)