Skip to content

-Wunused against lila #22642

Closed
Closed
@som-snytt

Description

@som-snytt

Compiler version

3.7.0-RC1-bin-SNAPSHOT

Minimized code

object Bus:

  type Payload            = Matchable
  type SubscriberFunction = PartialFunction[Payload, Unit]

  def pub[T <: Payload](payload: T)(using wc: WithChannel[T]) =
    publish(payload, wc.channel)

  def sub[T <: Payload: Typeable](f: PartialFunction[T, Unit])(using wc: WithChannel[T]) =
    subscribeFun(wc.channel):
      case x: T => f.applyOrElse(x, _ => ())

Output (click arrow to expand)

[error] java.lang.IndexOutOfBoundsException: 1
[error]         at scala.collection.LinearSeqOps.apply(LinearSeq.scala:131)
[error]         at scala.collection.LinearSeqOps.apply$(LinearSeq.scala:128)
[error]         at scala.collection.immutable.List.apply(List.scala:79)
[error]         at dotty.tools.dotc.transform.CheckUnused.transformSelect(CheckUnused.scala:72)
[error]         at dotty.tools.dotc.transform.CheckUnused.transformSelect(CheckUnused.scala:67)
[error]         at dotty.tools.dotc.transform.MegaPhase.goSelect(MegaPhase.scala:636)

which is

  override def transformSelect(tree: Select)(using Context): tree.type =
    val name = tree.removeAttachment(OriginalName).getOrElse(nme.NO_NAME)
    if tree.span.isSynthetic && tree.symbol == defn.TypeTest_unapply then
      tree.qualifier.tpe.underlying.finalResultType match
      case AppliedType(_, args) => // tycon.typeSymbol == defn.TypeTestClass
        val res = args(1) // T in TypeTest[-S, T]

Maybe because of the alias. The code here assumes there are two type args.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions