Skip to content

"cannot infer type; expected type <?> is not fully defined" for structural calls #9404

Closed
@sjrd

Description

@sjrd

Minimized code

import scala.reflect.Selectable.reflectiveSelectable

object Test {
  def main(args: Array[String]): Unit = {
    class Foo {
      def makeInt: Int = 5
      def testInt(x: Int): Unit = assert(5 == x)

      def makeRef: Option[String] = Some("hi")
      def testRef(x: Option[String]): Unit = assert(Some("hi") == x)
    }

    def test(foo: {
      def makeInt: Int
      def testInt(x: Int): Unit
      def makeRef: Option[String]
      def testRef(x: Option[String]): Unit
    }): Unit = {
      foo.testInt(foo.makeInt)
               //            ^
               // cannot infer type; expected type <?> is not fully defined
      foo.testRef(foo.makeRef)
               //            ^
               // cannot infer type; expected type <?> is not fully defined
    }

    test(new Foo)
  }
}

Output

-- Error: tests/run/hello.scala:24:29 ------------------------------------------
24 |      foo.testInt(foo.makeInt)
   |                             ^
   |               cannot infer type; expected type <?> is not fully defined
1 error found

(if we comment that line, the same error appears on the next line)

Expectation

All types are completely defined here, so I expect that there's nothing to be inferred, and therefore the "cannot infer type" error message doesn't make sense to me. I expect this code to compile and successfully run.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions