Skip to content

Wrong type inferred(?) in union type and implicit decorators part 2 #2745

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
felixmulder opened this issue Jun 13, 2017 · 1 comment
Closed

Comments

@felixmulder
Copy link
Contributor

The following does not compile:

object Test {
  type Result[A] = Errors | A
  final case class Errors(msgs: Seq[String])

  implicit class RichRes[A](val res: Result[A]) extends AnyVal {
    def map[B](f: A => B): Result[B] = res match {
      case xs: Errors => xs
      case a: A => f(a)
    }
  }

  val foo: Result[String] = ???
  def f(str: String): Int = ???

  foo.map(f(_)) // error
}
[error] -- [E007] Type Mismatch Error: /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala:67:13
[error] 67 |    x1.map(f(_))
[error]    |             ^
[error]    |found:    (dotty.tools.repl.results.Errors | dotty.tools.repl.ReplTyper.Success)(_$1)
[error]    |required: dotty.tools.repl.ReplTyper.Success
[error]    |
[error] one error found
[error] (dotty-repl/compile:compileIncremental) Compilation failed

ping @odersky

@sjrd
Copy link
Member

sjrd commented Jun 13, 2017

That would actually be a show-stopper for Scala.js to use type js.UndefOr[+A] = A | js.Undefined, which is something we'd like to do.

odersky added a commit that referenced this issue Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants