Skip to content

Polymorphic functions vs structural types #7653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Blaisorblade opened this issue Dec 1, 2019 · 1 comment · Fixed by #17474
Closed

Polymorphic functions vs structural types #7653

Blaisorblade opened this issue Dec 1, 2019 · 1 comment · Fixed by #17474

Comments

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Dec 1, 2019

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.

@ckipp01
Copy link
Member

ckipp01 commented May 11, 2023

The expectation of this is that it compiles:

//> using scala 3.3.1-RC1-bin-20230510-d6c643c-NIGHTLY

import reflect.Selectable.reflectiveSelectable

object options2 {
  type Option[T] = {
    def isEmpty: Boolean
  }
  type None[T] = Option[T]
  val none: () => Option[Nothing] = () =>
    new {
      def isEmpty = true
    }
  val mkNone0: [T] => () => Option[Nothing] = [T] =>
    () =>
      new {
        def isEmpty = true
    }
  val mkNone: [T] => () => Option[T] = [T] =>
    () =>
      new {
        def isEmpty = true
    }
}

This now does compile as expected, so I'll go ahead and close. Please report back or reopen if I'm misunderstanding something here.

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

Successfully merging a pull request may close this issue.

3 participants