Skip to content

Commit fa800a6

Browse files
committed
No warn for evidence params of marker traits such as NotGiven
1 parent 2f32850 commit fa800a6

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,16 @@ object CheckUnused:
602602
val dd = defn
603603
m.isDeprecated
604604
|| m.is(Synthetic)
605-
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
606-
|| sym.name.is(ContextBoundParamName) && sym.info.typeSymbol.isMarkerTrait // a ubiquitous parameter
607605
|| m.hasAnnotation(dd.UnusedAnnot) // param of unused method
606+
|| sym.name.is(ContextFunctionParamName) // a ubiquitous parameter
607+
|| sym.isCanEqual
608608
|| sym.info.typeSymbol.match // more ubiquity
609609
case dd.DummyImplicitClass | dd.SubTypeClass | dd.SameTypeClass => true
610-
case _ => false
610+
case tps =>
611+
tps.isMarkerTrait // no members to use; was only if sym.name.is(ContextBoundParamName)
612+
|| // but consider NotGiven
613+
tps.hasAnnotation(dd.LanguageFeatureMetaAnnot)
611614
|| sym.info.isSingleton // DSL friendly
612-
|| sym.isCanEqual
613-
|| sym.info.typeSymbol.hasAnnotation(dd.LanguageFeatureMetaAnnot)
614615
|| sym.info.isInstanceOf[RefinedType] // can't be expressed as a context bound
615616
if ctx.settings.WunusedHas.implicits
616617
&& !infos.skip(m)

Diff for: 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

Diff for: 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] = ()

Diff for: 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)