@@ -1429,6 +1429,27 @@ trait Checking {
14291429 em """ Implementation restriction: cannot generate CanThrow capability for this kind of catch.
14301430 |CanThrow capabilities can only be generated $req. """ ,
14311431 pat.srcPos)
1432+
1433+ /** (1) Check that every named import selector refers to a type or value member of the
1434+ * qualifier type.
1435+ * (2) Check that no import selector is renamed more than once.
1436+ */
1437+ def checkImportSelectors (qualType : Type , selectors : List [untpd.ImportSelector ])(using Context ): Unit =
1438+ val seen = mutable.Set .empty[Name ]
1439+
1440+ def checkIdent (sel : untpd.ImportSelector ): Unit =
1441+ if sel.name != nme.ERROR
1442+ && ! qualType.member(sel.name).exists
1443+ && ! qualType.member(sel.name.toTypeName).exists
1444+ then
1445+ report.error(NotAMember (qualType, sel.name, " value" ), sel.imported.srcPos)
1446+ if seen.contains(sel.name) then
1447+ report.error(ImportRenamedTwice (sel.imported), sel.imported.srcPos)
1448+ seen += sel.name
1449+
1450+ for sel <- selectors do
1451+ if ! sel.isWildcard then checkIdent(sel)
1452+ end checkImportSelectors
14321453}
14331454
14341455trait ReChecking extends Checking {
@@ -1466,4 +1487,5 @@ trait NoChecking extends ReChecking {
14661487 override def checkMembersOK (tp : Type , pos : SrcPos )(using Context ): Type = tp
14671488 override def checkInInlineContext (what : String , pos : SrcPos )(using Context ): Unit = ()
14681489 override def checkValidInfix (tree : untpd.InfixOp , meth : Symbol )(using Context ): Unit = ()
1490+ override def checkImportSelectors (qualType : Type , selectors : List [untpd.ImportSelector ])(using Context ): Unit = ()
14691491}
0 commit comments