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

Ambiguous type printing gives rise to confusing type errors #5398

Closed
scabug opened this issue Jan 23, 2012 · 4 comments
Closed

Ambiguous type printing gives rise to confusing type errors #5398

scabug opened this issue Jan 23, 2012 · 4 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 23, 2012

Scala's compiler prints several types ambiguously.

For example:

  • functions that takes n arguments of type A, B, C, .. and functions that take a single n-tuple (A, B, C, ...) argument.
  • higher-order functions (A => B) => C and curried functions A => B => C.

This can produce some confusing type errors such as

scala> k(z)
<console>:10: error: type mismatch;
&nbsp;found : Int => Int => Int
&nbsp;required: Int => Int => Int

Or

scala> h(g)
<console>:10: error: type mismatch;
&nbsp;found : (Int, Int) => Int
&nbsp;required: (Int, Int) => Int

Here's a gist of how to set up these particular type errors: https://gist.github.com/1655807

@scabug
Copy link
Author

scabug commented Jan 23, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5398?orig=1
Reporter: Noah Luck Easterly (rampion)
Affected Versions: 2.9.1
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Jan 23, 2012

@paulp said:
Please search for existing tickets before opening new ones. Already fixed in trunk. However all is not lost, I used this ticket as motivation to backport those two commits for 2.9.2.

scala> def k( j : (Int => Int) => Int ) : Int = j(_+1)
k: (j: (Int => Int) => Int)Int

scala> def p(q : Int => Int) : Int = q(0)
p: (q: Int => Int)Int

scala> def z = (x : Int) => (y : Int) => x + y
z: Int => (Int => Int)

scala> k(p)
res0: Int = 1

scala> k(z)
<console>:10: error: type mismatch;
 found   : Int => (Int => Int)
 required: (Int => Int) => Int
              k(z)
                ^

@scabug scabug closed this as completed Jan 23, 2012
@scabug
Copy link
Author

scabug commented Jan 23, 2012

@paulp said:
Oh, and

scala> h(g)
<console>:11: error: type mismatch;
 found   : ((Int, Int)) => Int
 required: (Int, Int) => Int
              h(g)
                ^

@scabug
Copy link
Author

scabug commented Jan 23, 2012

Noah Luck Easterly (rampion) said:
Awesome, thanks. Sorry I didn't notice this was already fixed in trunk. I'll be sure to spread the word.

@scabug scabug added the repl label Apr 7, 2017
@scabug scabug added this to the 2.9.2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants