Skip to content

Commit 61be637

Browse files
som-snytttgodzik
authored andcommitted
Use result of lambda type of implicit in CheckUnused (scala#23497)
Fixes scala#23494 When inspecting unused implicit parameters, the check skips parameters which are "marker traits". It tests for any members of the type (or its upper bound) which are not "universal members". This commit uses the `resultType` to avoid an error ``` invalid new prefix ``` while computing members where the type is a `LambdaType`. A future improvement would be not to request `allMembers`, since the check only needs to find one that is not universal. The necessitating change was scala@2e4bc0a.
1 parent 4d235ad commit 61be637

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ object CheckUnused:
964964
def isCanEqual: Boolean =
965965
sym.isOneOf(GivenOrImplicit) && sym.info.finalResultType.baseClasses.exists(_.derivesFrom(defn.CanEqualClass))
966966
def isMarkerTrait: Boolean =
967-
sym.info.hiBound.allMembers.forall: d =>
967+
sym.info.hiBound.resultType.allMembers.forall: d =>
968968
val m = d.symbol
969969
!m.isTerm || m.isSelfSym || m.is(Method) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass)
970970
def isEffectivelyPrivate: Boolean =

tests/warn/i15503f.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Wunused:implicits
1+
//> using options -Wunused:implicits
22

33
/* This goes around the "trivial method" detection */
44
val default_int = 1
@@ -58,6 +58,8 @@ package givens:
5858
trait Y:
5959
def doY: String
6060

61+
trait Z
62+
6163
given X with
6264
def doX = 7
6365

@@ -75,6 +77,9 @@ package givens:
7577

7678
given namely (using x: X): Y with // warn protected param to given class
7779
def doY = "8"
80+
81+
def f(using => X) = println() // warn
82+
def g(using => Z) = println() // nowarn marker trait
7883
end givens
7984

8085
object i22895:

tests/warn/i23494.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//> using options -Wunused:implicits
2+
3+
import scala.deriving.Mirror
4+
5+
abstract class EnumerationValues[A]:
6+
type Out
7+
8+
object EnumerationValues:
9+
type Aux[A, B] = EnumerationValues[A] { type Out = B }
10+
11+
def apply[A, B](): EnumerationValues.Aux[A, B] = new EnumerationValues[A]:
12+
override type Out = B
13+
14+
given sum[A, B <: Tuple](using mirror: Mirror.SumOf[A] { type MirroredElemTypes = B }): EnumerationValues.Aux[A, A] =
15+
EnumerationValues[A, A]()

0 commit comments

Comments
 (0)