Skip to content
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

Infer return types of new constructor calls #439

Open
illicitonion opened this issue Jun 13, 2019 · 1 comment
Open

Infer return types of new constructor calls #439

illicitonion opened this issue Jun 13, 2019 · 1 comment
Labels

Comments

@illicitonion
Copy link
Collaborator

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
@wiwa wiwa added the Language label Jun 14, 2019
@wiwa
Copy link
Contributor

wiwa commented Jun 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants