Skip to content

Commit 8203e0c

Browse files
committed
Remember language imports when expanding toplevel symbols
1 parent 7ae6e8e commit 8203e0c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
786786
case CapturesAndResult(refs, parent) =>
787787
changePrec(GlobalPrec)("^{" ~ Text(refs.map(toText), ", ") ~ "}" ~ toText(parent))
788788
case ContextBoundTypeTree(tycon, pname, ownName) =>
789-
toText(pname) ~ " is " ~ toText(tycon) ~ (" as " ~ toText(ownName) `provided` !ownName.isEmpty)
789+
toText(pname) ~ " : " ~ toText(tycon) ~ (" as " ~ toText(ownName) `provided` !ownName.isEmpty)
790790
case _ =>
791791
tree.fallbackToText(this)
792792
}

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class ImportInfo(symf: Context ?=> Symbol,
180180
assert(myUnimported != null)
181181
myUnimported.uncheckedNN
182182

183-
private val isLanguageImport: Boolean = untpd.languageImport(qualifier).isDefined
184-
185183
private var myUnimported: Symbol | Null = uninitialized
186184

187185
private var featureCache: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.empty

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ class Namer { typer: Typer =>
296296
createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
297297
(fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan))
298298
case tree: Import =>
299-
recordSym(newImportSymbol(ctx.owner, Completer(tree)(ctx), tree.span), tree)
299+
recordSym(newImportSym(tree), tree)
300300
case _ =>
301301
NoSymbol
302302
}
303303
}
304304

305+
private def newImportSym(imp: Import)(using Context): Symbol =
306+
newImportSymbol(ctx.owner, Completer(imp)(ctx), imp.span)
307+
305308
/** If `sym` exists, enter it in effective scope. Check that
306309
* package members are not entered twice in the same run.
307310
*/
@@ -706,7 +709,18 @@ class Namer { typer: Typer =>
706709
enterSymbol(companion)
707710
end addAbsentCompanions
708711

709-
stats.foreach(expand)
712+
/** Expand each statement, keeping track of language imports in the context. This is
713+
* necessary since desugaring might depend on language imports.
714+
*/
715+
def expandTopLevel(stats: List[Tree])(using Context): Unit = stats match
716+
case (imp @ Import(qual, _)) :: stats1 if untpd.languageImport(qual).isDefined =>
717+
expandTopLevel(stats1)(using ctx.importContext(imp, newImportSym(imp)))
718+
case stat :: stats1 =>
719+
expand(stat)
720+
expandTopLevel(stats1)
721+
case Nil =>
722+
723+
expandTopLevel(stats)
710724
mergeCompanionDefs()
711725
val ctxWithStats = stats.foldLeft(ctx)((ctx, stat) => indexExpanded(stat)(using ctx))
712726
inContext(ctxWithStats) {

0 commit comments

Comments
 (0)