Skip to content

Commit

Permalink
format and ObjectRef
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Jul 19, 2023
1 parent c4182ed commit d850968
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform
private def isInaccessibleField(tree: Tree)(using Context): Boolean =
val symbol = tree.symbol
symbol.isField &&
symbol.owner.isType &&
!isTermAccessible(symbol.asTerm, getQualifierTypeSymbol(tree))
symbol.owner.isType &&
!isTermAccessible(symbol.asTerm, getQualifierTypeSymbol(tree))

/**
* The symbol is a real method and the expression class cannot access it
Expand All @@ -147,8 +147,8 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform
private def isInaccessibleMethod(tree: Tree)(using Context): Boolean =
val symbol = tree.symbol
!isOwnedByExpression(symbol) &&
symbol.isRealMethod &&
(!symbol.owner.isType || !isTermAccessible(symbol.asTerm, getQualifierTypeSymbol(tree)))
symbol.isRealMethod &&
(!symbol.owner.isType || !isTermAccessible(symbol.asTerm, getQualifierTypeSymbol(tree)))

/**
* The symbol is a constructor and the expression class cannot access it
Expand All @@ -159,8 +159,8 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform
): Boolean =
val symbol = tree.symbol
!isOwnedByExpression(symbol) &&
symbol.isConstructor &&
(isInaccessibleMethod(tree) || !symbol.owner.isStatic)
symbol.isConstructor &&
(isInaccessibleMethod(tree) || !symbol.owner.isStatic)

private def getCapturer(variable: TermSymbol)(using
Context
Expand Down Expand Up @@ -237,8 +237,7 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform
.drop(1)
.take(target)
.foldLeft(ths) { (innerObj, outerSym) =>
if innerObj == ths && exprCtx.localVariables.contains("$outer") then
getLocalOuter(tree)(outerSym)
if innerObj == ths && exprCtx.localVariables.contains("$outer") then getLocalOuter(tree)(outerSym)
else getOuter(tree)(innerObj, outerSym)
}
else nullLiteral
Expand Down Expand Up @@ -420,7 +419,6 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform
!symbol.isRoot &&
!isOwnedByExpression(symbol)


private def isLocalVariable(symbol: Symbol)(using Context): Boolean =
!symbol.is(Method) && symbol.isLocalToBlock && !isOwnedByExpression(symbol)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes
Evaluation.success("B.b3", "b3"),
Evaluation.success("A.B.b3", "b3"),
Evaluation.success("B.b4", "b4"),
Evaluation.success("C")(result => assert(result.startsWith("A$C$@"))),
Evaluation.success("D")(result => assert(result.startsWith("A$D$@"))),
Evaluation.success("C", ObjectRef("A$C$")),
Evaluation.success("D", ObjectRef("A$D$")),
Evaluation.success("F.f1", "f1"),
Evaluation.success("F.f2", "f2"),
Evaluation.success("F.G")(result => assert(result.startsWith("F$G$@"))),
Evaluation.success("F.H")(result => assert(result.startsWith("F$H$@")))
Evaluation.success("F.G", ObjectRef("F$G$")),
Evaluation.success("F.H", ObjectRef("F$H$"))
)
)
}
Expand Down Expand Up @@ -2041,7 +2041,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes
}

test("i485: public members from private subclass") {
val source =
val source =
"""|package example
|
|class A {
Expand All @@ -2068,8 +2068,8 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes
Evaluation.success("b.a2 = 2", ()),
Evaluation.success("b.a2", 2),
Evaluation.success("b.m", "m"),
Evaluation.success("new b.D")(result => assert(result.startsWith("A$D@"))),
Evaluation.success("b.D")(result => assert(result.startsWith("A$D$@")))
Evaluation.success("new b.D", ObjectRef("A$D")),
Evaluation.success("b.D", ObjectRef("A$D$"))
)
}

Expand Down Expand Up @@ -2101,7 +2101,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes
Breakpoint(6),
Evaluation.success("x", "x"),
Breakpoint(8),
Evaluation.success("x", "x"),
Evaluation.success("x", "x")
)
} else {
check(
Expand Down

0 comments on commit d850968

Please sign in to comment.