Skip to content

Commit b7b0b2e

Browse files
authored
No warn for evidence params of marker traits such as NotGiven (#22985)
Fixes #22969
2 parents aeb09a7 + 32defdf commit b7b0b2e

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,16 @@ object CheckUnused:
627627
val dd = defn
628628
m.isDeprecated
629629
|| m.is(Synthetic)
630-
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
631-
|| sym.name.is(ContextBoundParamName) && sym.info.typeSymbol.isMarkerTrait // a ubiquitous parameter
632630
|| m.hasAnnotation(dd.UnusedAnnot) // param of unused method
631+
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
632+
|| sym.isCanEqual
633633
|| sym.info.typeSymbol.match // more ubiquity
634634
case dd.DummyImplicitClass | dd.SubTypeClass | dd.SameTypeClass => true
635-
case _ => false
635+
case tps =>
636+
tps.isMarkerTrait // no members to use; was only if sym.name.is(ContextBoundParamName)
637+
|| // but consider NotGiven
638+
tps.hasAnnotation(dd.LanguageFeatureMetaAnnot)
636639
|| sym.info.isSingleton // DSL friendly
637-
|| sym.isCanEqual
638-
|| sym.info.typeSymbol.hasAnnotation(dd.LanguageFeatureMetaAnnot)
639640
|| sym.info.isInstanceOf[RefinedType] // can't be expressed as a context bound
640641
if ctx.settings.WunusedHas.implicits
641642
&& !infos.skip(m)

tests/warn/i15503f.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait T
1919
object T:
2020
def hole(using T) = ()
2121

22-
class C(using T) // warn
22+
class C(using T) // no warn marker trait is evidence only
2323

2424
class D(using T):
2525
def t = T.hole // nowarn
@@ -53,7 +53,8 @@ object Unmatched:
5353
case _ =>
5454
e
5555

56-
trait Ctx
56+
trait Ctx:
57+
val state: Int
5758
case class K(i: Int)(using val ctx: Ctx) // nowarn
5859
class L(val i: Int)(using val ctx: Ctx) // nowarn
5960
class M(val i: Int)(using ctx: Ctx) // warn

tests/warn/i22969.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//> using options -Werror -Wunused:all
2+
import scala.util.NotGiven
3+
4+
object Test {
5+
def f[T](a: Int)(using NotGiven[T <:< Int]) = a + 2
6+
}
7+
8+
trait Furthermore:
9+
type Intish[A] = A <:< Int
10+
def f[A: Intish] = ()

tests/warn/scala2-t11681.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ trait Anonymous {
9898
}
9999
trait Context[A]
100100
trait Implicits {
101-
def f[A](implicit ctx: Context[A]) = answer // warn implicit param even though only marker
101+
def f[A](implicit ctx: Context[A]) = answer // no warn after all; previously, warn implicit param even though marker
102102
def g[A: Context] = answer // no warn bound that is marker only
103103
}
104104
class Bound[A: Context] // no warn bound that is marker only

0 commit comments

Comments
 (0)