Skip to content

Unable to find member method #6247

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
abeln opened this issue Apr 5, 2019 · 0 comments
Closed

Unable to find member method #6247

abeln opened this issue Apr 5, 2019 · 0 comments
Labels

Comments

@abeln
Copy link
Contributor

abeln commented Apr 5, 2019

For the explicit nulls project, we want to have an extension method that strips away nullability:

implicit class NN[T](x:T|Null) {
  def nn: T = x.asInstanceOf[T]
}

This works must of the time, but weirdly fails in the code below:

class Foo {
  val x1: String|Null = null
  x1.nn.length
  val x2: String = x1.nn
  x1.nn.length
}

-- [E008] Member Not Found Error: kk.scala:10:8 --------------------------------
10 |  x1.nn.length
   |  ^^^^^^^^^^^^
   |  value length is not a member of T
   |
   |  where:    T is a type variable with constraint >: String
one error found

Line 10 is the second x1.nn.length. However, both

class Foo {
  val x1: String|Null = null
  x1.nn.length
  // val x2: String = x1.nn <---------- commented out
  x1.nn.length
}

and

class Foo {
  val x1: String|Null = null
  x1.nn.length
  val x2 = x1.nn // <---------- the type of `x2` is inferred
  x1.nn.length
}

typecheck fine.

@liufengyun any hints about what could be going here?

@abeln abeln added area:typer area:implicits related to implicits labels Apr 5, 2019
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 7, 2019
This solves a situation where we cannot find a member `m` of a qualifier of type `T`
where `T` is a type variable with lower bound `L`, where `m` is a member of `L`.
This has come up occasionally before, but never until now in minimized form. The
solution is to instantiate the type variable using `fullyDefinedType` and try again.
smarter added a commit to dotty-staging/dotty that referenced this issue Apr 14, 2019
The check relied on the assumption that `locked` is always contained in
`state.ownedVars`, but this can stop being true when an owned type
variable is garbage-collected.
smarter added a commit to dotty-staging/dotty that referenced this issue Apr 15, 2019
The check relied on the assumption that `locked` is always contained in
`state.ownedVars`, but this can stop being true when an owned type
variable is garbage-collected.
smarter added a commit that referenced this issue Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants