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

improve error message for a type mismatch with right-associative method #4701

Closed
scabug opened this issue Jun 16, 2011 · 2 comments
Closed

Comments

@scabug
Copy link

scabug commented Jun 16, 2011

Given the following class that emulates a particular aspect of prepending to an HList:

scala> class A {
  def ::[T](x: T) : Option[T] = Some(x)
}
defined class A

scala> val a = new A
a: A = A@62d5b9c1

and usage:

scala> val b: Option[String] = 3 :: a
<console>:9: error: type mismatch;
 found   : Int(3)
 required: String
       val b: Option[String] = 3 :: a
                                 ^

scala> val b: Option[String] = a.::(3)
<console>:9: error: type mismatch;
 found   : Int(3)
 required: String
       val b: Option[String] = a.::(3)
                                    ^

The direct call syntax in the second case produces a more useful error message than the first case.

@scabug
Copy link
Author

scabug commented Jun 16, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4701?orig=1
Reporter: @harrah
See #4876

@scabug
Copy link
Author

scabug commented Aug 6, 2011

@soc said:
Weird. In 2.10.0.r25445-b20110805020350 the "(3)" is missing in the first case:

scala> val b: Option[String] = 3 :: a
<console>:9: error: type mismatch;
 found   : Int
 required: String
       val b: Option[String] = 3 :: a
                                 ^

scala> val b: Option[String] = a.::(3)
<console>:9: error: type mismatch;
 found   : Int(3)
 required: String
       val b: Option[String] = a.::(3)
                                    ^

hrhino added a commit to hrhino/scala that referenced this issue Jan 1, 2020
To preserve evaluation order, `x :: y` is rewritten not to `y.::(x)` but
to `{ val x$1 = x; y.::(x$1) }`. But, the `Ident(x$1)` tree is the
target of any type-mismatch errors issued later on, so it should steal
the position of `x` for the error message.

The important effect of this important change:
```
% diff /code/scala/test/files/neg/t4701-neg.log /code/scala/test/files/neg/t4701.check--- t4701-neg.log
+++ t4701.check
@@ -4,3 +4,3 @@
   hasType[HL[String]](nnn :: HN) // type mismatch error should have position at `nnn`
-                          ^
+                      ^
```

Fixes scala/bug#4701
@lrytz lrytz added this to the 2.12.11 milestone Jan 9, 2020
@lrytz lrytz closed this as completed Jan 9, 2020
@scala scala deleted a comment from scabug Jan 9, 2020
@scala scala deleted a comment from scabug Jan 9, 2020
@scala scala deleted a comment from scabug Jan 9, 2020
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

3 participants