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

Not accurate type inference in for-comprhension #15216

Closed
WojciechMazur opened this issue May 18, 2022 · 2 comments · Fixed by #15343
Closed

Not accurate type inference in for-comprhension #15216

WojciechMazur opened this issue May 18, 2022 · 2 comments · Fixed by #15343
Assignees
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented May 18, 2022

Type inferred inside for-comprehension is a union Any | X where X is expected

Compiler version

3.1.2
Works with 3.1.1
Fails in 3.1.3-RC3
Fails in 3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY

Minimized code

Based on https://github.com/vigoo/clipp/blob/8def1b439039fc8ddc74f55d8f58a337d11f919c/clipp-core/src/test/scala/io/github/vigoo/clipp/UsageInfoSpecs.scala#L94-L108

//> using scala "3.1.2"
// //> using scala "3.1.1" // Last working stable version

sealed abstract class Free[S[_], A] {
  final def map[B](f: A => B): Free[S, B] = ???
  final def flatMap[B](f: A => Free[S, B]): Free[S, B] = new Free[S, B] {}
}

trait Parameter[T]
def namedDouble(name: String): Free[Parameter, Double] = ???

type Double2 = (Double, Double)
type Double3 = (Double, Double, Double)
val spec: Free[Parameter, Either[Double3, Double2]] = for {
  result <-
    if (???) {
      for {
        x <- namedDouble("X")
        y <- namedDouble("Y")
        z <- namedDouble("Z")
      } yield Left((x, y, z))
    } else {
      for {
        x <- namedDouble("X")
        y <- namedDouble("Y")
      } yield Right((x, y))
    }
} yield result

Output

[error] ./test.scala:28:9: Found:    (result : Either[Any | (Double, Double, Double), (Double, Double) | Any])
[error] Required: Either[Double3, Double2]
[error] } yield result
[error]         ^^^^^^

Expectation

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 18, 2022
@griggt
Copy link
Contributor

griggt commented May 18, 2022

First bad commit is 3ab18a9

@smarter
Copy link
Member

smarter commented May 19, 2022

Might be a duplicate of #14494

@nicolasstucki nicolasstucki added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 19, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants