Skip to content

Commit f699811

Browse files
committed
No warn implicit param of abstract type as empty interface
1 parent a97b162 commit f699811

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,16 @@ object CheckUnused:
905905
def isCanEqual: Boolean =
906906
sym.isOneOf(GivenOrImplicit) && sym.info.finalResultType.baseClasses.exists(_.derivesFrom(defn.CanEqualClass))
907907
def isMarkerTrait: Boolean =
908-
sym.isClass && sym.info.allMembers.forall: d =>
909-
val m = d.symbol
910-
!m.isTerm || m.isSelfSym || m.is(Method) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass)
908+
def isEmptyInterface(info: Type): Boolean =
909+
info.allMembers.forall: d =>
910+
val m = d.symbol
911+
!m.isTerm || m.isSelfSym || m.is(Method) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass)
912+
if sym.isClass then isEmptyInterface(sym.info)
913+
else if sym.is(Deferred) then
914+
sym.info match
915+
case TypeBounds(_, hi) => hi == defn.AnyType || isEmptyInterface(hi)
916+
case _ => true
917+
else false
911918
def isEffectivelyPrivate: Boolean =
912919
sym.is(Private, butNot = ParamAccessor)
913920
|| sym.owner.isAnonymousClass && !sym.isEffectivelyOverride

tests/warn/i17314.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Wunused:all -deprecation -feature
1+
//> using options -Wunused:all -deprecation -feature -Werror
22

33
import java.net.URI
44

@@ -10,7 +10,7 @@ object circelike {
1010
type Configuration
1111
trait ConfiguredCodec[T]
1212
object ConfiguredCodec:
13-
inline final def derived[A](using conf: Configuration)(using inline mirror: Mirror.Of[A]): ConfiguredCodec[A] = // warn
13+
inline final def derived[A](using conf: Configuration)(using inline mirror: Mirror.Of[A]): ConfiguredCodec[A] =
1414
class InlinedConfiguredCodec extends ConfiguredCodec[A]:
1515
val codec = summonInline[Codec[URI]] // simplification
1616
new InlinedConfiguredCodec

tests/warn/i23250b.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//> using options -Wunused:all
2+
3+
trait Memberly:
4+
def member: Int
5+
6+
object Members:
7+
type MemberType <: Memberly
8+
type Empty
9+
10+
object Test:
11+
import Members.*
12+
13+
type MT = MemberType
14+
def membered(using MT) = println() // warn abstract type offers member in upper bound
15+
def remembered(using mt: MT) = mt.member
16+
17+
type Ignore = Empty
18+
def emptily(using Ignore) = println()

0 commit comments

Comments
 (0)