twitter / rsc

Experimental Scala compiler focused on compilation speed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infer return types of `new` constructor calls

illicitonion opened this issue · comments

Ideally each of these shouldn't need explicit type ascription:

package examples.pure_scala

object Lib {
  def h1 = new String("hello")

  val h2 = new String("hi")
}

because it's super obvious what the types are, but they currently do:

src/examples/pure_scala/Lib.scala:4: error: No type found at src/examples/pure_scala/Lib.scala@3:2..3:30 for definition: def <examples/pure_scala/Lib.h1().> = new String("hello")
  def h1 = new String("hello")
  ^
src/examples/pure_scala/Lib.scala:6: error: No type found at src/examples/pure_scala/Lib.scala@5:2..5:27 for definition: val def <examples/pure_scala/Lib.h2.> = new String("hi")
  val h2 = new String("hi")
  ^
two errors found

A naive implementation would break for polymorphic constructors:

class C[A](x: A)

val x = new C(1) // should be inferred as x: C[Int] but would need to infer into C's constructor