scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

CC: Increase Precision of Errors for Lambdas

Open bracevac opened this issue 3 months ago • 0 comments

Compiler version

3.8 nightly

Minimized code

I noticed that typing issues stemming from CC in closures/lambdas will point to the start of the block and not the actual line causing the issues, as seen in the test case fa3863f.

Output

Here is the first error message from that test:

-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/classifiers-secondclass.scala:41:28 ----------------------
41 |      parReduce(1 to 1000): (a, b) => // error
   |                            ^
   |Found:    (a: Int, b: Int) ->{f.write, f.read} Int
   |Required: (Int, Int) ->{cap.only[Read]} Int
   |
   |Note that capability f.write is not included in capture set {cap.only[Read]}.
   |
   |where:    cap is a fresh root capability created in anonymous function of type (f²: Levels.File^): Unit when checking argument to parameter op of method parReduce
42 |        f.write(42)         // the error stems from here
43 |        a + b + f.read()    // ok
   |
   | longer explanation available when compiling with `-explain`

Expectation

The error marker should point to this line instead

42 |        f.write(42)         // the error stems from here

bracevac avatar Aug 26 '25 14:08 bracevac