Skip to content

Commit

Permalink
Fix scala#9176: Handle parent call argument effects in full mode
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Nov 29, 2020
1 parent 299e048 commit be53c79
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
28 changes: 17 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/init/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ object Checking {
checkSecondaryConstructor(ctor)
}

(stats :+ expr).foreach { stat =>
val summary = Summarization.analyze(stat)(theEnv.withOwner(ctor))
checkStats(stats :+ expr, ctor)
}

def checkStats(stats: List[Tree], owner: Symbol)(using state: State): Unit =
stats.foreach { stat =>
val summary = Summarization.analyze(stat)(theEnv.withOwner(owner))
checkEffects(summary.effs)
}
}

cls.paramAccessors.foreach { acc =>
if (!acc.is(Flags.Method)) {
Expand All @@ -155,16 +158,19 @@ object Checking {
}

tpl.parents.foreach {
case tree @ Block(_, parent) =>
val (ctor, _, _) = decomposeCall(parent)
case tree @ Block(stats, parent) =>
val (ctor, _, argss) = decomposeCall(parent)
if theEnv.isFullMode then checkStats((stats :: argss).flatten, cls)
checkConstructor(ctor.symbol, parent.tpe, tree)

case tree @ Apply(Block(_, parent), _) =>
val (ctor, _, _) = decomposeCall(parent)
case tree @ Apply(Block(stats, parent), args) =>
val (ctor, _, argss) = decomposeCall(parent)
if theEnv.isFullMode then checkStats((stats :: argss).flatten, cls)
checkConstructor(ctor.symbol, tree.tpe, tree)

case parent : Apply =>
val (ctor, _, argss) = decomposeCall(parent)
if theEnv.isFullMode then checkStats(argss.flatten, cls)
checkConstructor(ctor.symbol, parent.tpe, parent)

case ref =>
Expand Down Expand Up @@ -203,13 +209,13 @@ object Checking {
val errors = state.check(MethodCall(pot, sym)(source))
if errors.nonEmpty then return errors

// if sym.name.isTermName && !sym.isOneOf(Flags.Method | Flags.Private) && sym.hasSource then
// val errors = state.check(Promote(FieldReturn(pot, sym)(source))(source))
// if errors.nonEmpty then return errors
if sym.name.isTermName && !sym.isOneOf(Flags.Method | Flags.Private) && sym.hasSource then
val errors = state.check(Promote(FieldReturn(pot, sym)(source))(source))
if errors.nonEmpty then return errors
}

// best-effort in fast mode
// if !theEnv.isFullMode then return Errors.empty
if !theEnv.isFullMode then return Errors.empty

val excludedFlags = Flags.Deferred | Flags.Private | Flags.Protected

Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ class CompilationTests {
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init/full/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init/pos", options).checkCompile()
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/init/full/neg/global-cycle1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object A {
val a: Int = B.b // error
}

object B {
val b: Int = A.a // error
}

@main
def Test = print(A.a)
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/init/full/neg/i9176.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo(val opposite: Foo)
case object A extends Foo(B) // error
case object B extends Foo(A) // error
object Test {
def main(args: Array[String]): Unit = {
println(A.opposite)
println(B.opposite)
}
}

0 comments on commit be53c79

Please sign in to comment.