File tree 4 files changed +16
-3
lines changed
compiler/src/dotty/tools/dotc
4 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -442,7 +442,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
442
442
443
443
/** The purity level of this reference.
444
444
* @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
446
448
* IdempotentPath if reference is lazy and stable
447
449
* Impure otherwise
448
450
* @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] =>
452
454
val sym = tree.symbol
453
455
if (! tree.hasType) Impure
454
456
else if (! tree.tpe.widen.isParameterless || sym.isEffectivelyErased) PurePath
457
+ else if tree.tpe.isInstanceOf [ConstantType ] then PurePath
455
458
else if (! sym.isStableMember) Impure
456
459
else if (sym.is(Module ))
457
460
if (sym.moduleClass.isNoInitsClass) PurePath else IdempotentPath
Original file line number Diff line number Diff line change @@ -727,7 +727,7 @@ object SymDenotations {
727
727
*/
728
728
final def isStableMember (implicit ctx : Context ): Boolean = {
729
729
def isUnstableValue = isOneOf(UnstableValueFlags ) || info.isInstanceOf [ExprType ]
730
- isType || is(StableRealizable ) || ! isUnstableValue
730
+ isType || is(StableRealizable ) || exists && ! isUnstableValue
731
731
}
732
732
733
733
/** Is this a denotation of a class that does not have - either direct or inherited -
Original file line number Diff line number Diff line change @@ -1082,7 +1082,7 @@ object Types {
1082
1082
/** Widen type if it is unstable (i.e. an ExprType, or TermRef to unstable symbol */
1083
1083
final def widenIfUnstable (implicit ctx : Context ): Type = stripTypeVar match {
1084
1084
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
1086
1086
case _ => this
1087
1087
}
1088
1088
Original file line number Diff line number Diff line change
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' ))
You can’t perform that action at this time.
0 commit comments