Skip to content

Commit 10603ca

Browse files
committed
Handle language feature imports
1 parent 6dd9d1f commit 10603ca

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ class ImportInfo(symf: Context ?=> Symbol,
207207
def test(prefix: TermName, feature: TermName): Option[Boolean] =
208208
untpd.languageImport(qualifier) match
209209
case Some(`prefix`) =>
210-
if forwardMapping.contains(feature) then Some(true)
210+
if forwardMapping.contains(feature) then
211+
ctx.usages.use(this, selectors(selectorOf(feature)))
212+
Some(true)
211213
else if excluded.contains(feature) then Some(false)
212214
else None
213215
case _ => None

tests/neg/unused-imports.check

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
-- [E007] Type Mismatch Error: tests/neg/unused-imports.scala:8:15 -----------------------------------------------------
2-
8 | def i: Int = "42" // error sanity check
3-
| ^^^^
4-
| Found: ("42" : String)
5-
| Required: Int
6-
|
7-
| longer explanation available when compiling with `-explain`
8-
-- Error: tests/neg/unused-imports.scala:3:24 --------------------------------------------------------------------------
9-
3 |import scala.concurrent.* // error
1+
-- [E007] Type Mismatch Error: tests/neg/unused-imports.scala:11:15 ----------------------------------------------------
2+
11 | def i: Int = "42" // error sanity check
3+
| ^^^^
4+
| Found: ("42" : String)
5+
| Required: Int
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- Error: tests/neg/unused-imports.scala:5:16 --------------------------------------------------------------------------
9+
5 |import language.postfixOps // error
10+
| ^^^^^^^^^^
11+
| Unused import
12+
-- Error: tests/neg/unused-imports.scala:6:24 --------------------------------------------------------------------------
13+
6 |import scala.concurrent.* // error
1014
| ^
1115
| Unused import
12-
-- Error: tests/neg/unused-imports.scala:9:77 --------------------------------------------------------------------------
13-
9 | import scala.collection.mutable.{HashMap => GoodMap, Seq => _, ListBuffer, Buffer, Set => OK} // error // error
14-
| ^^^^^^
15-
| Unused import
16-
-- Error: tests/neg/unused-imports.scala:9:43 --------------------------------------------------------------------------
17-
9 | import scala.collection.mutable.{HashMap => GoodMap, Seq => _, ListBuffer, Buffer, Set => OK} // error // error
18-
| ^^^^^^^^^^^^^^^^^^
19-
| Unused import
16+
-- Error: tests/neg/unused-imports.scala:12:43 -------------------------------------------------------------------------
17+
12 | import scala.collection.mutable.{HashMap as GoodMap, Seq as _, ListBuffer, Buffer, Set as OK} // error // error
18+
| ^^^^^^^^^^^^^^^^^^
19+
| Unused import
20+
-- Error: tests/neg/unused-imports.scala:12:77 -------------------------------------------------------------------------
21+
12 | import scala.collection.mutable.{HashMap as GoodMap, Seq as _, ListBuffer, Buffer, Set as OK} // error // error
22+
| ^^^^^^
23+
| Unused import

tests/neg/unused-imports.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// scalac: -Wunused:imports -Werror -Ydebug
1+
// scalac: -Wunused:imports -Werror -Ydebug -feature
22

33
//import language.future
4+
import language.implicitConversions
5+
import language.postfixOps // error
46
import scala.concurrent.* // error
57
import scala.concurrent.ExecutionContext.Implicits.*
68

@@ -51,3 +53,12 @@ object Givens:
5153
given cOrdering: Ordering[C] with
5254
override def compare(c0: C, c1: C) = 0
5355
val greeting = "we love Givens"
56+
57+
class A:
58+
def f(b: B): Unit = b.f(this)
59+
60+
object A:
61+
implicit val a2b: Conversion[A, B] = _ => B()
62+
63+
class B:
64+
def f(b: B): Unit = ()

0 commit comments

Comments
 (0)