Skip to content
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

regression: ensuring on ??? #5249

Closed
olhotak opened this issue Oct 12, 2018 · 3 comments
Closed

regression: ensuring on ??? #5249

olhotak opened this issue Oct 12, 2018 · 3 comments

Comments

@olhotak
Copy link
Contributor

olhotak commented Oct 12, 2018

My use case is to give students a method with an empty body and a postcondition, and to ask them to complete the body so it satisfies the postcondition:

object test {
   def m(x: Int): Int = {
     ???
   } ensuring(ans => ans == x)
}

This compiles with Dotty 0.7.0 but Dotty master gives:

-- [E008] Member Not Found Error: inferEnsuring.scala:4:5 ----------------------
2 |   def m(x: Int): Int = {
3 |     ???
  |                        ^
  |                        value `ensuring` is not a member of Nothing
one error found

Since ensuring is a member of Int and since Nothing <: Int, ensuring should also be a member of Nothing.

Although the member is injected by an implicit conversion to Ensuring, the same reasoning applies: the implicit conversion applies to every subtype of Any, and Nothing <: Any.

@liufengyun
Copy link
Contributor

Since ensuring is a member of Int and since Nothing <: Int, ensuring should also be a member of Nothing.

This is not the case for Scala when it is related to Null, Nothing.

scala> def f(x: Nothing): Int = x + 3
<console>:11: error: value + is not a member of Nothing
       def f(x: Nothing): Int = x + 3
                                  ^

scala> def f(x: Null): Int = x + 3
<console>:11: error: value + is not a member of Null
       def f(x: Null): Int = x + 3
                               ^

And in some cases GADT bounds:

case class One[T](fst: T)

object Test {
  def bad[T](e: One[T])(x: T): Int = e match {
    case foo: One[Int] =>
      x + 4
  }
}

/cc: @AleksanderBG The code above compiles in Scalac, but not in Dotty.

@odersky
Copy link
Contributor

odersky commented Mar 8, 2020

The behavior on Null and Nothing is as expected. I leave to @AleksanderBG to decide whether the GADT example should compile or not.

@abgruszecki
Copy link
Contributor

Closing as a duplicate of #7044 - we do infer GADT bound T := Int (and we do want to infer it), but member selection on x.+ fails.

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

No branches or pull requests

5 participants