Skip to content

Commit 423db5f

Browse files
committed
Infrastructure for import implied.
Interpretation of what `implied` means is still missing.
1 parent b305597 commit 423db5f

27 files changed

+96
-74
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ object desugar {
392392
if (isEnum) {
393393
val (enumCases, enumStats) = stats.partition(DesugarEnums.isEnumCase)
394394
val enumCompanionRef = new TermRefTree()
395-
val enumImport = Import(enumCompanionRef, enumCases.flatMap(caseIds))
395+
val enumImport = Import(impliedOnly = false, enumCompanionRef, enumCases.flatMap(caseIds))
396396
(enumImport :: enumStats, enumCases, enumCompanionRef)
397397
}
398398
else (stats, Nil, EmptyTree)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
358358
def statPurity(tree: Tree)(implicit ctx: Context): PurityLevel = unsplice(tree) match {
359359
case EmptyTree
360360
| TypeDef(_, _)
361-
| Import(_, _)
361+
| Import(_, _, _)
362362
| DefDef(_, _, _, _, _) =>
363363
Pure
364364
case vdef @ ValDef(_, _, _) =>

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ object Trees {
762762
* where a selector is either an untyped `Ident`, `name` or
763763
* an untyped thicket consisting of `name` and `rename`.
764764
*/
765-
case class Import[-T >: Untyped] private[ast] (expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
765+
case class Import[-T >: Untyped] private[ast] (impliedOnly: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
766766
extends DenotingTree[T] {
767767
type ThisTree[-T >: Untyped] = Import[T]
768768
}
@@ -1156,9 +1156,9 @@ object Trees {
11561156
case tree: Template if (constr eq tree.constr) && (parents eq tree.parents) && (derived eq tree.derived) && (self eq tree.self) && (body eq tree.unforcedBody) => tree
11571157
case tree => finalize(tree, untpd.Template(constr, parents, derived, self, body)(tree.source))
11581158
}
1159-
def Import(tree: Tree)(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1160-
case tree: Import if (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1161-
case _ => finalize(tree, untpd.Import(expr, selectors)(tree.source))
1159+
def Import(tree: Tree)(impliedOnly: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1160+
case tree: Import if (impliedOnly == tree.impliedOnly) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1161+
case _ => finalize(tree, untpd.Import(impliedOnly, expr, selectors)(tree.source))
11621162
}
11631163
def PackageDef(tree: Tree)(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match {
11641164
case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree
@@ -1303,8 +1303,8 @@ object Trees {
13031303
cpy.TypeDef(tree)(name, transform(rhs))
13041304
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
13051305
cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body))
1306-
case Import(expr, selectors) =>
1307-
cpy.Import(tree)(transform(expr), selectors)
1306+
case Import(impliedOnly, expr, selectors) =>
1307+
cpy.Import(tree)(impliedOnly, transform(expr), selectors)
13081308
case PackageDef(pid, stats) =>
13091309
cpy.PackageDef(tree)(transformSub(pid), transformStats(stats)(localCtx))
13101310
case Annotated(arg, annot) =>
@@ -1427,7 +1427,7 @@ object Trees {
14271427
this(x, rhs)
14281428
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
14291429
this(this(this(this(x, constr), parents), self), tree.body)
1430-
case Import(expr, selectors) =>
1430+
case Import(impliedOnly, expr, selectors) =>
14311431
this(x, expr)
14321432
case PackageDef(pid, stats) =>
14331433
this(this(x, pid), stats)(localCtx)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
329329
Block(cdef :: Nil, New(cls.typeRef, Nil))
330330
}
331331

332-
def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
333-
ta.assignType(untpd.Import(expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
332+
def Import(impliedOnly: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
333+
ta.assignType(untpd.Import(impliedOnly, expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
334334

335335
def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
336336
ta.assignType(untpd.PackageDef(pid, stats), pid)

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
326326
def Template(constr: DefDef, parents: List[Tree], derived: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template =
327327
if (derived.isEmpty) new Template(constr, parents, self, body)
328328
else new DerivingTemplate(constr, parents ++ derived, self, body, derived.length)
329-
def Import(expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(expr, selectors)
329+
def Import(impliedOnly: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(impliedOnly, expr, selectors)
330330
def PackageDef(pid: RefTree, stats: List[Tree])(implicit src: SourceFile): PackageDef = new PackageDef(pid, stats)
331331
def Annotated(arg: Tree, annot: Tree)(implicit src: SourceFile): Annotated = new Annotated(arg, annot)
332332

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ object Contexts {
404404
case ref: RefTree[_] => Some(ref.name.asTermName)
405405
case _ => None
406406
}
407-
ctx.fresh.setImportInfo(new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt))
407+
ctx.fresh.setImportInfo(
408+
new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt, imp.impliedOnly))
408409
}
409410

410411
/** Does current phase use an erased types interpretation? */

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,8 @@ object SymDenotations {
18721872
maybeAdd(name)
18731873
val ownSyms =
18741874
if (keepOnly eq implicitFilter)
1875-
if (this is Package) Iterator.empty // !!!!
1875+
if (this is Package) Iterator.empty
1876+
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
18761877
else info.decls.iterator filter (_ is ImplicitOrImplied)
18771878
else info.decls.iterator
18781879
for (sym <- ownSyms) maybeAdd(sym.name)

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Standard-Section: "ASTs" TopLevelStat*
5858
ValOrDefDef
5959
TYPEDEF Length NameRef (type_Term | Template) Modifier*
6060
OBJECTDEF Length NameRef Template Modifier*
61-
IMPORT Length qual_Term Selector*
61+
IMPORT Length [IMPLIED] qual_Term Selector*
6262
ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier*
6363
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
6464
Modifier*

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,13 @@ class TreePickler(pickler: TastyPickler) {
532532
}
533533
pickleStats(tree.constr :: rest)
534534
}
535-
case Import(expr, selectors) =>
535+
case Import(impliedOnly, expr, selectors) =>
536536
writeByte(IMPORT)
537-
withLength { pickleTree(expr); pickleSelectors(selectors) }
537+
withLength {
538+
if (impliedOnly) writeByte(IMPLIED)
539+
pickleTree(expr)
540+
pickleSelectors(selectors)
541+
}
538542
case PackageDef(pid, stats) =>
539543
writeByte(PACKAGE)
540544
withLength { pickleType(pid.tpe); pickleStats(stats) }

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,10 @@ class TreeUnpickler(reader: TastyReader,
956956
assert(sourcePathAt(start).isEmpty)
957957
readByte()
958958
readEnd()
959+
val impliedOnly = nextByte == IMPLIED
960+
if (impliedOnly) readByte()
959961
val expr = readTerm()
960-
setSpan(start, Import(expr, readSelectors()))
962+
setSpan(start, Import(impliedOnly, expr, readSelectors()))
961963
}
962964

963965
def readSelectors()(implicit ctx: Context): List[untpd.Tree] = nextByte match {

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10491049
val to = untpd.Ident(toName)
10501050
if (toName.isEmpty) from else untpd.Thicket(from, untpd.Ident(toName))
10511051
})
1052-
1053-
Import(expr, selectors)
1052+
Import(impliedOnly = false, expr, selectors)
10541053

10551054
case TEMPLATEtree =>
10561055
setSym()

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Completion {
6767
if (name.span.contains(pos.span)) Mode.Import
6868
else Mode.None // Can't help completing the renaming
6969

70-
case Import(_, _) :: _ =>
70+
case Import(_, _, _) :: _ =>
7171
Mode.Import
7272

7373
case _ =>
@@ -84,7 +84,7 @@ object Completion {
8484
case Thicket(name :: _ :: Nil) :: (_: Import) :: _ =>
8585
completionPrefix(name :: Nil, pos)
8686

87-
case Import(expr, selectors) :: _ =>
87+
case Import(_, expr, selectors) :: _ =>
8888
selectors.find(_.span.contains(pos.span)).map { selector =>
8989
completionPrefix(selector.asInstanceOf[Tree] :: Nil, pos)
9090
}.getOrElse("")
@@ -120,10 +120,10 @@ object Completion {
120120

121121
if (buffer.mode != Mode.None) {
122122
path match {
123-
case Select(qual, _) :: _ => buffer.addMemberCompletions(qual)
124-
case Import(expr, _) :: _ => buffer.addMemberCompletions(expr)
125-
case (_: Thicket) :: Import(expr, _) :: _ => buffer.addMemberCompletions(expr)
126-
case _ => buffer.addScopeCompletions
123+
case Select(qual, _) :: _ => buffer.addMemberCompletions(qual)
124+
case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish implied from non-implied
125+
case (_: Thicket) :: Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr)
126+
case _ => buffer.addScopeCompletions
127127
}
128128
}
129129

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ object JavaParsers {
603603
}
604604

605605
def importCompanionObject(cdef: TypeDef): Tree =
606-
Import(Ident(cdef.name.toTermName).withSpan(NoSpan), Ident(nme.WILDCARD) :: Nil)
606+
Import(impliedOnly = false, Ident(cdef.name.toTermName).withSpan(NoSpan), Ident(nme.WILDCARD) :: Nil)
607607

608608
// Importing the companion object members cannot be done uncritically: see
609609
// ticket #2377 wherein a class contains two static inner classes, each of which
@@ -665,7 +665,7 @@ object JavaParsers {
665665
// case nme.WILDCARD => Pair(ident, Ident(null) withPos Span(-1))
666666
// case _ => Pair(ident, ident)
667667
// }
668-
val imp = atSpan(start) { Import(qual, List(ident)) }
668+
val imp = atSpan(start) { Import(impliedOnly = false, qual, List(ident)) }
669669
imp :: Nil
670670
}
671671
}

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,11 +2157,13 @@ object Parsers {
21572157
def finalizeDef(md: MemberDef, mods: Modifiers, start: Int): md.ThisTree[Untyped] =
21582158
md.withMods(mods).setComment(in.getDocComment(start))
21592159

2160-
/** Import ::= import ImportExpr {`,' ImportExpr}
2160+
/** Import ::= import [implied] [ImportExpr {`,' ImportExpr}
21612161
*/
21622162
def importClause(): List[Tree] = {
21632163
val offset = accept(IMPORT)
2164-
commaSeparated(importExpr) match {
2164+
val impliedOnly = in.token == IMPLIED
2165+
if (impliedOnly) in.nextToken()
2166+
commaSeparated(importExpr(impliedOnly)) match {
21652167
case t :: rest =>
21662168
// The first import should start at the start offset of the keyword.
21672169
val firstPos =
@@ -2174,21 +2176,24 @@ object Parsers {
21742176

21752177
/** ImportExpr ::= StableId `.' (id | `_' | ImportSelectors)
21762178
*/
2177-
val importExpr: () => Import = () => path(thisOK = false, handleImport) match {
2178-
case imp: Import =>
2179-
imp
2180-
case sel @ Select(qual, name) =>
2181-
val selector = atSpan(pointOffset(sel)) { Ident(name) }
2182-
cpy.Import(sel)(qual, selector :: Nil)
2183-
case t =>
2184-
accept(DOT)
2185-
Import(t, Ident(nme.WILDCARD) :: Nil)
2186-
}
2179+
def importExpr(impliedOnly: Boolean): () => Import = {
21872180

2188-
val handleImport: Tree => Tree = { tree: Tree =>
2189-
if (in.token == USCORE) Import(tree, importSelector() :: Nil)
2190-
else if (in.token == LBRACE) Import(tree, inBraces(importSelectors()))
2191-
else tree
2181+
val handleImport: Tree => Tree = { tree: Tree =>
2182+
if (in.token == USCORE) Import(impliedOnly, tree, importSelector() :: Nil)
2183+
else if (in.token == LBRACE) Import(impliedOnly, tree, inBraces(importSelectors()))
2184+
else tree
2185+
}
2186+
2187+
() => path(thisOK = false, handleImport) match {
2188+
case imp: Import =>
2189+
imp
2190+
case sel @ Select(qual, name) =>
2191+
val selector = atSpan(pointOffset(sel)) { Ident(name) }
2192+
cpy.Import(sel)(impliedOnly, qual, selector :: Nil)
2193+
case t =>
2194+
accept(DOT)
2195+
Import(impliedOnly, t, Ident(nme.WILDCARD) :: Nil)
2196+
}
21922197
}
21932198

21942199
/** ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}'

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
479479
typeDefText(tparamsTxt, optText(rhs)(" = " ~ _))
480480
}
481481
recur(rhs, "")
482-
case Import(expr, selectors) =>
482+
case Import(impliedOnly, expr, selectors) =>
483483
def selectorText(sel: Tree): Text = sel match {
484484
case Thicket(l :: r :: Nil) => toTextGlobal(l) ~ " => " ~ toTextGlobal(r)
485485
case _ => toTextGlobal(sel)
@@ -488,7 +488,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
488488
case id :: Nil => toText(id)
489489
case _ => "{" ~ Text(selectors map selectorText, ", ") ~ "}"
490490
}
491-
keywordStr("import ") ~ toTextLocal(expr) ~ "." ~ selectorsText
491+
keywordText("import ") ~ (keywordText("implied ") provided impliedOnly) ~
492+
toTextLocal(expr) ~ "." ~ selectorsText
492493
case packageDef: PackageDef =>
493494
packageDefText(packageDef)
494495
case tree: Template =>

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,11 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
339339
tree match {
340340
case Match(selector, _) =>
341341
addPatMatDependency(selector.tpe)
342-
case Import(expr, selectors) =>
343-
def lookupImported(name: Name) = expr.tpe.member(name).symbol
342+
case Import(impliedOnly, expr, selectors) =>
343+
def lookupImported(name: Name) = {
344+
val sym = expr.tpe.member(name).symbol
345+
if (sym.is(Implied) == impliedOnly) sym else NoSymbol
346+
}
344347
def addImported(name: Name) = {
345348
// importing a name means importing both a term and a type (if they exist)
346349
addMemberRefDependency(lookupImported(name.toTermName))

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
2020
}
2121

2222
def ImportDeco(imp: Import): ImportAPI = new ImportAPI {
23+
def impliedOnly: Boolean = imp.impliedOnly
2324
def expr(implicit ctx: Context): Tree = imp.expr
2425
def selectors(implicit ctx: Context): List[ImportSelector] = imp.selectors
2526
}
@@ -208,14 +209,14 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
208209
}
209210

210211
object Import extends ImportModule {
211-
def apply(expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import =
212-
tpd.Import(expr, selectors)
212+
def apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import =
213+
tpd.Import(impliedOnly, expr, selectors)
213214

214-
def copy(original: Import)(expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import =
215-
tpd.cpy.Import(original)(expr, selectors)
215+
def copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import =
216+
tpd.cpy.Import(original)(impliedOnly, expr, selectors)
216217

217-
def unapply(x: Tree)(implicit ctx: Context): Option[(Term, List[ImportSelector])] = x match {
218-
case x: tpd.Import => Some((x.expr, x.selectors))
218+
def unapply(x: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] = x match {
219+
case x: tpd.Import => Some((x.impliedOnly, x.expr, x.selectors))
219220
case _ => None
220221
}
221222
}

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
300300
case tree: LambdaTypeTree =>
301301
VarianceChecker.checkLambda(tree)
302302
super.transform(tree)
303-
case Import(expr, selectors) =>
303+
case Import(_, expr, selectors) =>
304304
val exprTpe = expr.tpe
305305
val seen = mutable.Set.empty[Name]
306306
def checkIdent(ident: untpd.Ident): Unit = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ trait Checking {
972972
val cases =
973973
for (stat <- impl.body if isCase(stat))
974974
yield untpd.Ident(stat.symbol.name.toTermName)
975-
val caseImport: Import = Import(ref(cdef.symbol), cases)
975+
val caseImport: Import = Import(impliedOnly = false, ref(cdef.symbol), cases)
976976
val caseCtx = enumCtx.importContext(caseImport, caseImport.symbol)
977977
for (stat <- impl.body) checkCaseOrDefault(stat, caseCtx)
978978
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FrontEnd extends Phase {
6666

6767
private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match {
6868
case PackageDef(_, defs) :: _ => firstTopLevelDef(defs)
69-
case Import(_, _) :: defs => firstTopLevelDef(defs)
69+
case Import(_, _, _) :: defs => firstTopLevelDef(defs)
7070
case (tree @ TypeDef(_, _)) :: _ => tree.symbol
7171
case _ => NoSymbol
7272
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ object ImportInfo {
1616
def rootImport(refFn: () => TermRef)(implicit ctx: Context): ImportInfo = {
1717
val selectors = untpd.Ident(nme.WILDCARD) :: Nil
1818
def expr(implicit ctx: Context) = tpd.Ident(refFn())
19-
def imp(implicit ctx: Context) = tpd.Import(expr, selectors)
20-
new ImportInfo(implicit ctx => imp.symbol, selectors, None, isRootImport = true)
19+
def imp(implicit ctx: Context) = tpd.Import(impliedOnly = false, expr, selectors)
20+
new ImportInfo(implicit ctx => imp.symbol, selectors, None, impliedOnly = false, isRootImport = true)
2121
}
2222
}
2323

@@ -26,11 +26,14 @@ object ImportInfo {
2626
* @param selectors The selector clauses
2727
* @param symNameOpt Optionally, the name of the import symbol. None for root imports.
2828
* Defined for all explicit imports from ident or select nodes.
29+
* @param impliedOnly true if this is an implied import
2930
* @param isRootImport true if this is one of the implicit imports of scala, java.lang,
3031
* scala.Predef or dotty.DottyPredef in the start context, false otherwise.
3132
*/
3233
class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
33-
symNameOpt: Option[TermName], val isRootImport: Boolean = false) extends Showable {
34+
symNameOpt: Option[TermName],
35+
val impliedOnly: Boolean,
36+
val isRootImport: Boolean = false) extends Showable {
3437

3538
// Dotty deviation: we cannot use a lazy val here for the same reason
3639
// that we cannot use one for `DottyPredefModuleRef`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ class Typer extends Namer
17791779
val expr1 = typedExpr(imp.expr, AnySelectionProto)
17801780
checkStable(expr1.tpe, imp.expr.sourcePos)
17811781
if (!ctx.isAfterTyper) checkRealizable(expr1.tpe, imp.expr.posd)
1782-
assignType(cpy.Import(imp)(expr1, imp.selectors), sym)
1782+
assignType(cpy.Import(imp)(imp.impliedOnly, expr1, imp.selectors), sym)
17831783
}
17841784

17851785
def typedPackageDef(tree: untpd.PackageDef)(implicit ctx: Context): Tree = track("typedPackageDef") {

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
327327
328328
Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args)
329329
330-
Import ::= ‘import’ ImportExpr {‘,’ ImportExpr}
330+
Import ::= ‘import’ [‘implied’] ImportExpr {‘,’ ImportExpr}
331331
ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels)
332332
ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’
333333
ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] Ident(name), Pair(id, id)

0 commit comments

Comments
 (0)