Skip to content

Fix #8058: Fix isStableMember test #8062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>

/** The purity level of this reference.
* @return
* PurePath if reference is (nonlazy and stable) or to a parameterized function
* PurePath if reference is (nonlazy and stable)
* or to a parameterized function
* or its type is a constant type
* IdempotentPath if reference is lazy and stable
* Impure otherwise
* @DarkDimius: need to make sure that lazy accessor methods have Lazy and Stable
Expand All @@ -452,6 +454,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
val sym = tree.symbol
if (!tree.hasType) Impure
else if (!tree.tpe.widen.isParameterless || sym.isEffectivelyErased) PurePath
else if tree.tpe.isInstanceOf[ConstantType] then PurePath
else if (!sym.isStableMember) Impure
else if (sym.is(Module))
if (sym.moduleClass.isNoInitsClass) PurePath else IdempotentPath
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ object SymDenotations {
*/
final def isStableMember(implicit ctx: Context): Boolean = {
def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType]
isType || is(StableRealizable) || !isUnstableValue
isType || is(StableRealizable) || exists && !isUnstableValue
}

/** Is this a denotation of a class that does not have - either direct or inherited -
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ object Types {
/** Widen type if it is unstable (i.e. an ExprType, or TermRef to unstable symbol */
final def widenIfUnstable(implicit ctx: Context): Type = stripTypeVar match {
case tp: ExprType => tp.resultType.widenIfUnstable
case tp: TermRef if !tp.symbol.isStableMember => tp.underlying.widenIfUnstable
case tp: TermRef if tp.symbol.exists && !tp.symbol.isStableMember => tp.underlying.widenIfUnstable
case _ => this
}

Expand Down
10 changes: 10 additions & 0 deletions tests/run/i8058.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extension on (x: Array[Char]):
inline def swap(i: Int, j: Int) : Unit =
val v = x(i)
x(i) = x(j)
x(j) = v

@main def Test =
val a = Array('A','B')
a.swap(0, 1)
assert(a.toList == List('B', 'A'))