Skip to content

Fix a REPL bad symbolic reference #19775

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

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,23 @@ object Symbols extends SymUtils {
private def computeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
util.Stats.record("Symbol.computeDenot")
val now = ctx.period
val prev = checkedPeriod
checkedPeriod = now
if (lastd.validFor contains now) lastd else recomputeDenot(lastd)
if lastd.validFor.contains(now) then
lastd
else
val newd = recomputeDenot(lastd)
if newd.exists then
lastDenot = newd
else
checkedPeriod = prev
newd
}

/** Overridden in NoSymbol */
protected def recomputeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
util.Stats.record("Symbol.recomputeDenot")
val newd = lastd.current.asInstanceOf[SymDenotation]
lastDenot = newd
newd
lastd.current.asSymDenotation
}

/** The original denotation of this symbol, without forcing anything */
Expand Down
28 changes: 28 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,34 @@ class ReplCompilerTests extends ReplTest:
@Test def `i13097 expect template after colon` = contextually:
assert(ParseResult.isIncomplete("class C:"))

@Test def i15562: Unit = initially {
val s1 = run("List(1, 2).filter(_ % 2 == 0).foreach(println)")
assertEquals("2", storedOutput().trim)
s1
} andThen { s1 ?=>
val comp = tabComplete("List(1, 2).filter(_ % 2 == 0).fore")
assertEquals(List("foreach"), comp.distinct)
s1
} andThen {
val s2 = run("List(1, 2).filter(_ % 2 == 0).foreach(println)")
assertEquals("2", storedOutput().trim)
s2
}

@Test def i15562b: Unit = initially {
val s1 = run("List(1, 2).filter(_ % 2 == 0).foreach(println)")
assertEquals("2", storedOutput().trim)
s1
} andThen { s1 ?=>
val comp = tabComplete("val x = false + true; List(1, 2).filter(_ % 2 == 0).fore")
assertEquals(List("foreach"), comp.distinct)
s1
} andThen {
val s2 = run("List(1, 2).filter(_ % 2 == 0).foreach(println)")
assertEquals("2", storedOutput().trim)
s2
}

object ReplCompilerTests:

private val pattern = Pattern.compile("\\r[\\n]?|\\n");
Expand Down
4 changes: 4 additions & 0 deletions compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na

def contextually[A](op: Context ?=> A): A = op(using initialState.context)

/** Returns the `(<instance completions>, <companion completions>)`*/
def tabComplete(src: String)(implicit state: State): List[String] =
completions(src.length, src, state).map(_.value).sorted

extension [A](state: State)
infix def andThen(op: State ?=> A): A = op(using state)

Expand Down
4 changes: 0 additions & 4 deletions compiler/test/dotty/tools/repl/TabcompleteTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import org.junit.Test
/** These tests test input that has proved problematic */
class TabcompleteTests extends ReplTest {

/** Returns the `(<instance completions>, <companion completions>)`*/
private def tabComplete(src: String)(implicit state: State): List[String] =
completions(src.length, src, state).map(_.value).sorted

@Test def tabCompleteList = initially {
val comp = tabComplete("List.r")
assertEquals(List("range"), comp.distinct)
Expand Down