Skip to content

Polymorphic functions vs structural types #7653

Closed
@Blaisorblade

Description

@Blaisorblade

minimized code

The following code doesn't compile, but should:

package bug
import reflect.Selectable.reflectiveSelectable

object options2 {
  type Option[T] = {
    def isEmpty: Boolean
  }
  type None[T] = Option[T]
  //Succeeds:
  val none : () => Option[Nothing] = () => new {
    def isEmpty = true
  }
  //Fails. Note I'm not even using T!
  val mkNone0 : [T] => () => Option[Nothing] = [T] => () => new {
    def isEmpty = true
  }
  //Fails. That'd be real.
  val mkNone : [T] => () => Option[T] = [T] => () => new {
    def isEmpty = true
  }
}

expectation

Should compile.

actual

[error] -- [E007] Type Mismatch Error: /Users/pgiarrusso/git/Coq/silr-dot/code/Bug.scala:16:3
[error] 16 |  }
[error]    |   ^
[error]    |   Found:    Object with PolyFunction {...}
[error]    |   Required: PolyFunction{apply: [T](): bug.options2.Option[Nothing]}
[error] -- [E007] Type Mismatch Error: /Users/pgiarrusso/git/Coq/silr-dot/code/Bug.scala:20:3
[error] 20 |  }
[error]    |   ^
[error]    |   Found:    Object with PolyFunction {...}
[error]    |   Required: PolyFunction{apply: [T](): bug.options2.Option[T]}
[error] two errors found

With version 0.20.0-RC1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions