Skip to content

Type inference does not dealias type constructors enough to infer type arguments #8709

Open
@scabug

Description

@scabug

Scalac refuses to infer the type arguments of or below, in the definition of bippy. If however I inline the =?>: alias, it manages. I thought it was a regression, but it's there on every Scala I happen to have around (in 2.9.2, 2.10.3, 2.11.0 and 2.11.1).

object Bug {
  type =?>:[A, B] = PartialFunction[A, B]

  val ??? : Nothing = throw new Exception
  //Does not work.
  def or[T, U](f: T =?>: U)(g: T => U): T => U =
  //Works.
  //def or[T, U](f: PartialFunction[T, U])(g: T => U): T => U =
    //x => f applyOrElse (x, g) //Works in everything but 2.9
    ???

  def bar: String =?>: String = ???
  def foo: String => String = ???
  def bippy: String => String =
    or(bar orElse bar)(foo)
}

In 2.11.0:

<console>:21: error: type mismatch;
 found   : PartialFunction[String,String]
 required: Bug.=?>:[T,String]
    (which expands to)  PartialFunction[T,String]
           or(bar orElse bar)(foo)
                  ^

In 2.9.2:

<console>:21: error: type mismatch;
 found   : PartialFunction[String,String]
 required: Bug.=?>:[T,String]
           or(bar orElse bar)(foo)
                  ^

Random/fun facts:

What's more fun is that when or and its clients are in different files: introducing the breakage in the interface won't change the SBT interface "hash", so the client will not be recompiled right away, only when you're least expecting it (say, you clean).

Original instance here:
inc-lc/ilc-scala@bea1580#diff-c23523827d5e9b210d097946ecae4a46L6

Error witnessed also on Travis below
https://travis-ci.org/inc-lc/ilc-scala/jobs/29252425

I thought it was a duplicate, but the only similar issue (at least superficially) seems #3777.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dealiascompiler isn't dealiasing when it should, or vice versainfer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions