From abffc806d535df7252b73add51de5d93f89bcb5f Mon Sep 17 00:00:00 2001 From: Paul Coral Date: Fri, 13 Jan 2023 20:55:20 +0100 Subject: [PATCH] Fix registering Ident not containing a symbol - Register their type - Fix #16680 - Update test suit --- .../src/dotty/tools/dotc/transform/CheckUnused.scala | 7 ++++++- tests/neg-custom-args/fatal-warnings/i15503a.scala | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index b9076ea4b6c0..e3e4c31d2cb6 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -81,7 +81,12 @@ class CheckUnused extends MiniPhase: ctx override def prepareForIdent(tree: tpd.Ident)(using Context): Context = - _key.unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name))) + if tree.symbol.exists then + _key.unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name))) + else if tree.hasType then + _key.unusedDataApply(_.registerUsed(tree.tpe.classSymbol, Some(tree.name))) + else + ctx override def prepareForSelect(tree: tpd.Select)(using Context): Context = _key.unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name))) diff --git a/tests/neg-custom-args/fatal-warnings/i15503a.scala b/tests/neg-custom-args/fatal-warnings/i15503a.scala index c626fd88085e..868c488ddb84 100644 --- a/tests/neg-custom-args/fatal-warnings/i15503a.scala +++ b/tests/neg-custom-args/fatal-warnings/i15503a.scala @@ -255,4 +255,14 @@ package foo.testing.imports.precedence: package foo.test.enums: enum A: // OK case B extends A // OK - case C extends A // OK \ No newline at end of file + case C extends A // OK + +package foo.test.typeapply.hklamdba.i16680: + package foo: + trait IO[A] + + package bar: + import foo.IO // OK + + def f[F[_]]: String = "hello" + def go = f[IO] \ No newline at end of file