Skip to content

Commit 970ac2d

Browse files
committed
Fix -Wunused:import for "<init>"
- Register owner of the constructor instead of the constructor. - This solves the issue where `member(sym.name)` have multiple identical names
1 parent 4fa0715 commit 970ac2d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import dotty.tools.dotc.core.Definitions
2727
import dotty.tools.dotc.core.Types.ConstantType
2828
import dotty.tools.dotc.core.NameKinds.WildcardParamName
2929
import dotty.tools.dotc.core.Types.TermRef
30+
import dotty.tools.dotc.core.Types.NameFilter
3031

3132

3233

@@ -326,9 +327,10 @@ object CheckUnused:
326327
*/
327328
def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit =
328329
if !isConstructorOfSynth(sym) && !doNotRegister(sym) then
329-
usedInScope.top += ((sym, sym.isAccessibleAsIdent, name))
330330
if sym.isConstructor && sym.exists then
331331
registerUsed(sym.owner, None) // constructor are "implicitly" imported with the class
332+
else
333+
usedInScope.top += ((sym, sym.isAccessibleAsIdent, name))
332334

333335
/** Register a symbol that should be ignored */
334336
def addIgnoredUsage(sym: Symbol)(using Context): Unit =

0 commit comments

Comments
 (0)