-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
//> using option -Wunused:imports | ||
|
||
import scala.compiletime.* | ||
import scala.deriving.* | ||
|
||
trait Foo | ||
|
||
trait HasFoo[A]: | ||
/** true if A contains a Foo */ | ||
val hasFoo: Boolean | ||
|
||
// given instances that need to be imported to be in scope | ||
object HasFooInstances: | ||
given defaultHasFoo[A]: HasFoo[A] with | ||
val hasFoo: Boolean = false | ||
given HasFoo[Foo] with | ||
val hasFoo: Boolean = true | ||
|
||
object HasFooDeriving: | ||
|
||
inline private def tupleHasFoo[T <: Tuple]: Boolean = | ||
inline erasedValue[T] match | ||
case _: EmptyTuple => false | ||
case _: (t *: ts) => summonInline[HasFoo[t]].hasFoo || tupleHasFoo[ts] | ||
|
||
inline def deriveHasFoo[T](using p: Mirror.ProductOf[T]): HasFoo[T] = | ||
// falsely reported as unused even though it has influence on this code | ||
import HasFooInstances.given // no warn at inline method | ||
val pHasFoo = tupleHasFoo[p.MirroredElemTypes] | ||
new HasFoo[T]: // warn New anonymous class definition will be duplicated at each inline site | ||
val hasFoo: Boolean = pHasFoo | ||
|
||
/* the import is used upon inline elaboration | ||
object Test: | ||
import HasFooDeriving.* | ||
case class C(x: Foo, y: Int) | ||
def f: HasFoo[C] = deriveHasFoo[C] | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//> using options -Wunused:all | ||
object Deps: | ||
trait D1 | ||
object D2 | ||
end Deps | ||
|
||
object Bug: | ||
import Deps.D1 // no warn | ||
|
||
class Cl(d1: D1): | ||
import Deps.* | ||
def f = (d1, D2) | ||
end Bug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
//> using option -Wunused:all | ||
|
||
@main def run = | ||
val veryUnusedVariable: Int = value // warn local | ||
|
||
package i20520: | ||
private def veryUnusedMethod(x: Int): Unit = println() // warn param | ||
private val veryUnusedVariableToplevel: Unit = println() // package members are accessible under separate compilation | ||
|
||
def value = 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//> using options -Wunused:all | ||
object Foo { | ||
val dummy = 42 | ||
def f(): Unit = Option(1).map((x: Int) => dummy) // warn | ||
def g(): Unit = Option(1).map((x: Int) => ???) // warn | ||
def main(args: Array[String]): Unit = {} | ||
} |