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

No type-mismatch error in fewer-braces code when using context function #20563

Open
WojciechMazur opened this issue Jun 13, 2024 · 0 comments
Open
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

3.4.2

Minimized example

trait Zone
object Zone:
  def apply[T](f: Zone ?=> T): T = ???

def foo(str: String)(using Zone): String = ???

def test: Int = Zone:
  val x = foo("bar")

Output Error/Warning message

[error] -- [E172] Type Error: /Users/wmazur/projects/scala-native/sandbox/src/main/scala/Test.scala:12:20 
[error] 12 |  val x = foo("bar")
[error]    |                    ^
[error]    |No given instance of type Zone was found for parameter x$2 of method foo
[error] one error found
[error] (sandbox3 / Compile / compileIncremental) Compilation failed

Why this Error/Warning was not helpful

There is no information about type-mismatch error that causes actual compilation error. Replacing fewer-braces block with braces

def test: Int = Zone {
  val x = foo("bar")
}

Produces 2 error messages:

[error] -- [E172] Type Error: /Users/wmazur/projects/scala-native/sandbox/src/main/scala/Test.scala:8:20 
[error] 8 |  val x = foo("bar")
[error]   |                    ^
[error]   |  No given instance of type Zone was found for parameter x$2 of method foo
[error] -- [E007] Type Mismatch Error: /Users/wmazur/projects/scala-native/sandbox/src/main/scala/Test.scala:9:1 
[error] 9 |}
[error]   | ^
[error]   | Found:    Unit
[error]   | Required: Int
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] two errors found

Suggested improvement

It should either report both messages or report only type mismatch error.

Case 2

Removing local variable makes the code report only missing implicit, even when using braces:

def test: Int = Zone {
  foo("bar")
}
[error] -- [E172] Type Error: /Users/wmazur/projects/scala-native/sandbox/src/main/scala/Test.scala:8:12 
[error] 8 |  foo("bar")
[error]   |            ^
[error]   |  No given instance of type Zone was found for parameter x$2 of method foo
[error] one error found
@WojciechMazur WojciechMazur added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc stat:needs triage Every issue needs to have an "area" and "itype" label better-errors Issues concerned with improving confusing/unhelpful diagnostic messages labels Jun 13, 2024
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants