Skip to content

Inferred return type of overridden method is forced to be pure #16535

Open
@Linyxus

Description

@Linyxus

Compiler version

main branch

Minimized code

import language.experimental.captureChecking

trait Cap { def use(): Unit }

def main(ct: {*} Cap, io: {*} Cap): Unit = {
  abstract class A {
    def foo(x: Int) = {
      () => { ct.use(); io.use(); x }
    }
  }

  class B extends A {
    override def foo(x: Int) = {
      () => { ct.use(); x }
    }
  }
}

Output

-- [E007] Type Mismatch Error: issues/method-inferred.scala:13:31 -----------------------------------------------------------------------------------------------------------------------------------------------
13 |    override def foo(x: Int) = {
   |                               ^
   |                               Found:    {ct} () -> Int
   |                               Required: () -> Int
14 |      () => { ct.use(); x }
15 |    }
   |
   | longer explanation available when compiling with `-explain`
1 error found

Expectation

This code should compile.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions