Closed
Description
Compiler version
3.3.0
Minimized code
//> using scala "3.3.0"
//> using options "-Wunused:locals"
class Record(elems: (String, Any)*) extends Selectable:
private val fields = elems.toMap
def selectDynamic(name: String): Any = fields(name)
type Person = Record { val name: String; val age: Int }
object Main {
locally {
def good: Person = ???
def bad1: Record { val name: String; val age: Int } = ???
def bad2 = (good: Record { val name: String; val age: Int })
(bad1, bad2)
}
}
Compile it with:
scalac -Wunused:locals Main.scala
Output
-- Warning: Main.scala:10:27 ---------------------------------------------------
10 | def bad1: Record { val name: String; val age: Int } = ???
| ^^^^
| unused local definition
-- Warning: Main.scala:10:45 ---------------------------------------------------
10 | def bad1: Record { val name: String; val age: Int } = ???
| ^^^
| unused local definition
-- Warning: Main.scala:11:35 ---------------------------------------------------
11 | def bad2 = (good: Record { val name: String; val age: Int })
| ^^^^
| unused local definition
-- Warning: Main.scala:11:53 ---------------------------------------------------
11 | def bad2 = (good: Record { val name: String; val age: Int })
| ^^^
| unused local definition
4 warnings found
Expectation
No warnings are issued.
Note that removing the locally
block and putting the definitions directly into Main
suppresses the warnings, presumably because they are no longer local.