Skip to content

Capability argument type becomes Nothing after avoidance #16226

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
Linyxus opened this issue Oct 20, 2022 · 0 comments · Fixed by #16261
Closed

Capability argument type becomes Nothing after avoidance #16226

Linyxus opened this issue Oct 20, 2022 · 0 comments · Fixed by #16261
Assignees
Labels
cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Oct 20, 2022

Compiler version

main branch

Minimized code

It is modified from the test case pos-custom-args/captures/lazyref.scala.

@annotation.capability class Cap

class LazyRef[T](val elem: () => T):
  val get: {elem} () -> T = elem
  def map[U](f: T => U): {f, this} LazyRef[U] =
    new LazyRef(() => f(elem()))

def map[A, B](ref: {*} LazyRef[A], f: A => B): {f, ref} LazyRef[B] =
  new LazyRef(() => f(ref.elem()))

def main(io: Cap) = {
  def mapd[A, B]: ({io} LazyRef[A], A => B) => {*} LazyRef[B] =
    (ref1, f1) => map[A, B](ref1, f1)
}

Output

-- [E007] Type Mismatch Error: issues/lazymap-avoid.scala:13:4 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 |    (ref1, f1) => map[A, B](ref1, f1)
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |    Found:    ? (ref1: {io} Nothing, f1: ? (x$0: ? A) -> ? B) -> {f1, ref1, io} LazyRef[? >: ? B <: ? B]{elem: {*} () -> box ? B}
   |    Required: ({io} LazyRef[A], A => B) => {io} LazyRef[B]
   |
   | longer explanation available when compiling with `-explain`
1 error found

Expectation

It should compile.

Trace of the avoidance call in recheckBlock during rechecking:

==> TypeOps.avoid(? (ref1: ? LazyRef[? A]{elem: ? () -> box ? A}, f1: ? (x$0: ? A) -> ? B) -> {f1, ref1} LazyRef[? B]{elem: {*} () -> box ? B}, [method $anonfun])?
<== TypeOps.avoid(? (ref1: ? LazyRef[? A]{elem: ? () -> box ? A}, f1: ? (x$0: ? A) -> ? B) -> {f1, ref1} LazyRef[? B]{elem: {*} () -> box ? B}, [method $anonfun]) = ? (ref1: ? Nothing, f1: ? (x$0: ? A) -> ? B) -> {f1, ref1} LazyRef[? >: ? B <: ? B]{elem: {*} () -> box ? B}

As seen here, during avoidance, the capability argument type becomes Nothing.

@Linyxus Linyxus added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 20, 2022
@dwijnand dwijnand added cc-experiment Intended to be merged with cc-experiment branch on origin and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 24, 2022
@odersky odersky self-assigned this Oct 29, 2022
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants