Skip to content

Imprecise type inferred with polymorphic type alias #6693

Closed
@fhackett

Description

@fhackett

Trying to compile this code yields an error I can't make sense of:

package towers.computes

import quoted._

sealed abstract class Computes[T]

object Computes {

  opaque type Opaque[T] = Int

  implicit class ComputesApplication1[T : Type](fn : Computes[Opaque[T]]) {
    def apply[A](arg1 : Computes[A]) : Computes[T] = ???
  }

  def let[V, T : Type](value : Computes[V], body : Computes[Opaque[T]]) : Computes[T] = body(value)
}

The error is:

[error] -- [E007] Type Mismatch Error: /home/finn/programming/polyparse/src/main/scala/Computes.scala:15:92
[error] 15 |  def let[V, T : Type](value : Computes[V], body : Computes[Opaque[T]]) : Computes[T] = body(value)
[error]    |                                                                                        ^^^^^^^^^^^
[error]    |                             Found:    towers.computes.Computes[Nothing]
[error]    |                             Required: towers.computes.Computes[T]

For some reason, the .apply method on ComputesApplication1 is determined to yield Computes[Nothing] instead of Computes[T] as the signature dictates.

While trying to minimise my example, here are some variations I tried:

  • Removing the : Type implicits prevents the bug from occurring.
  • Replacing Type with a trait declared trait SomeImplicit[T] does not cause the same issue
  • Removing only the : Type in the let method changes nothing, while it should fail because the ComputesApplication1 would then be missing an implicit it needs.
  • Removing the Computes[...] and just leaving Opaque[...] causes what's left to just compile normally

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions