Skip to content

No warn for evidence params of marker traits such as NotGiven #22985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,16 @@ object CheckUnused:
val dd = defn
m.isDeprecated
|| m.is(Synthetic)
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
|| sym.name.is(ContextBoundParamName) && sym.info.typeSymbol.isMarkerTrait // a ubiquitous parameter
|| m.hasAnnotation(dd.UnusedAnnot) // param of unused method
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
|| sym.isCanEqual
|| sym.info.typeSymbol.match // more ubiquity
case dd.DummyImplicitClass | dd.SubTypeClass | dd.SameTypeClass => true
case _ => false
case tps =>
tps.isMarkerTrait // no members to use; was only if sym.name.is(ContextBoundParamName)
|| // but consider NotGiven
tps.hasAnnotation(dd.LanguageFeatureMetaAnnot)
|| sym.info.isSingleton // DSL friendly
|| sym.isCanEqual
|| sym.info.typeSymbol.hasAnnotation(dd.LanguageFeatureMetaAnnot)
|| sym.info.isInstanceOf[RefinedType] // can't be expressed as a context bound
if ctx.settings.WunusedHas.implicits
&& !infos.skip(m)
Expand Down
5 changes: 3 additions & 2 deletions tests/warn/i15503f.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait T
object T:
def hole(using T) = ()

class C(using T) // warn
class C(using T) // no warn marker trait is evidence only

class D(using T):
def t = T.hole // nowarn
Expand Down Expand Up @@ -53,7 +53,8 @@ object Unmatched:
case _ =>
e

trait Ctx
trait Ctx:
val state: Int
case class K(i: Int)(using val ctx: Ctx) // nowarn
class L(val i: Int)(using val ctx: Ctx) // nowarn
class M(val i: Int)(using ctx: Ctx) // warn
Expand Down
10 changes: 10 additions & 0 deletions tests/warn/i22969.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//> using options -Werror -Wunused:all
import scala.util.NotGiven

object Test {
def f[T](a: Int)(using NotGiven[T <:< Int]) = a + 2
}

trait Furthermore:
type Intish[A] = A <:< Int
def f[A: Intish] = ()
2 changes: 1 addition & 1 deletion tests/warn/scala2-t11681.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ trait Anonymous {
}
trait Context[A]
trait Implicits {
def f[A](implicit ctx: Context[A]) = answer // warn implicit param even though only marker
def f[A](implicit ctx: Context[A]) = answer // no warn after all; previously, warn implicit param even though marker
def g[A: Context] = answer // no warn bound that is marker only
}
class Bound[A: Context] // no warn bound that is marker only
Expand Down
Loading