Skip to content

Instantly share code, notes, and snippets.

@Sciss
Last active January 5, 2016 13:40
Show Gist options
  • Select an option

  • Save Sciss/08c762e76cf5498e1084 to your computer and use it in GitHub Desktop.

Select an option

Save Sciss/08c762e76cf5498e1084 to your computer and use it in GitHub Desktop.

Highlight bugs

This file contains all the remaining highlight errors of IntelliJ in my code-base, for future reference and so that I don't report the same thing twice. Scala plug-in version last checked is: 2.0.3.

The code base for encountering these bugs is SoundProcesses. Line of wrong highlight is marked // !

Private setter wrongly marked as 'is never used'

class Foo {
  private var bar = 123
  
  def foo: Int = bar
  private def foo_=(x: Int): Unit = bar = x  // !
  
  def test(): Unit = foo = 456
}

Type inference fails with path-dependent type / type-projection involving HK type

trait Foo {
  trait Factory {
    type Repr[~]

    def apply[S](obj: Repr[S]): Any
  }

  def apply[S](map: Map[Int, Factory], tid: Int, obj: Any): Any =
    map.get(tid).fold(???)(f => f(obj.asInstanceOf[f.Repr[S]])) // !
}

Type highlight error with final class' type member, refinement of type argument, and pattern matching

object Foo {
  case class Output(i: Int)
  final case class Input() extends In {
    type Out = Output
  }

  trait In { type Out }

  def requestInput[Res](in: In { type Out = Res }): Res = in match { // !
    case Input() => Output(1234) // !
  }
}

Type mismatch, disconnection between refined type parameter/ path-dependent type and parameter value

object Foo {
  trait Sys[S <: Sys[S]] {
    type I <: Sys[I]
  }

  def apply[S <: Sys[S]](system: S): Any =
    prepare[S, system.I](system)   // !

  def prepare[S <: Sys[S], I1 <: Sys[I1]](system: S {type I = I1}): Any = ???
}

Methods on a method argument are not found any longer if argument type contains refinement

object Foo {
  trait Sys[S <: Sys[S]] {
    type I

    def foo(tx: Any): Any
  }

  def prepare[S <: Sys[S], I1 <: Sys[I1]](system: S { type I = I1 }): Any =
    system.foo(123)  // !
}

Type mismatch after aliasing-import a member from a higher-kinded value

object Foo {
  trait Sys[S <: Sys[S]]

  trait SkipMap[S <: Sys[S], A, B] {
    def add(entry: (A, B)): Option[B]
  }

  trait Output[S <: Sys[S]]

  class OutputImpl[S <: Sys[S]](proc: Proc[S]) extends Output[S] {
    import proc.{outputs => map}

    def add(key: String, value: Output[S]): Unit =
      map.add(key -> value)   // !
  }

  trait Proc[S <: Sys[S]] {
    def outputs: SkipMap[S, String, Output[S]]
  }
}

Implicit conversion resolution does not take numeric widening into account

object Foo {
  object Values {
    implicit def fromFloat(x: Float): Values = ???
  }
  trait Values
  
  def foo(value: Values) = ()

  foo(0)  // !
}

Combining intersection type and higher-kinded type ("...doesn't conform to expected type")

trait Bug {
  type Foo[_]
  type Bar[_]
  type S

  def foo(): Foo[S] with Bar[S]

  def test(): Unit = {
    val x: Foo[S] = foo()  // !
  }
}

Failing to isolate

The following highlight bugs cannot be implemented using a reduced example apparently

Illegal inheritance with mixins

Modelled after de.sciss.synth.proc.impl.DurableImpl:

object Foo {

  trait Sys[S <: Sys[S]]

  trait DurableLike [D <: DurableLike [D]] extends Sys[D]
  trait InMemoryLike[I <: InMemoryLike[I]] extends Sys[I]

  trait InMemory extends InMemoryLike[InMemory] with Sys[InMemory]

  type D[S <: DurableLike[S]] = DurableLike[S]

  trait ReactionMap[S <: Sys[S]]

  trait Mixin[S <: D[S], I <: Sys[I]] extends DurableLike[S] with ReactionMap[S] {
    system =>
  }
}

object Bar {
  import Foo._
  trait ProcSys[S <: ProcSys[S]] extends Sys[S]

  trait ProcDurable  extends DurableLike [ProcDurable ] with ProcSys[ProcDurable ]
  trait ProcInMemory extends InMemoryLike[ProcInMemory] with ProcSys[ProcInMemory]
}

object Baz {
  import Foo._
  import Bar._

  private final class System()
    extends Mixin[ProcDurable, ProcInMemory] with ProcDurable {
  }
}

In the original code, this produces an error "Illegal inheritance, self-type DurableImpl.System does not conform to DurableImpl.Mixin[S, Any]".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment