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

Better error reporting is required for inlined non-immutable paths #21538

Closed
soronpo opened this issue Sep 4, 2024 · 5 comments · Fixed by #21639
Closed

Better error reporting is required for inlined non-immutable paths #21538

soronpo opened this issue Sep 4, 2024 · 5 comments · Fixed by #21639
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement Spree Suitable for a future Spree
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Sep 4, 2024

As discovered in #16804 and raised again in #17181 and #21536, it is clear that better error reporting is required to prevent further ticket opening, by suggesting to remove the inline from the dependent argument in the compiler error message.

Compiler version

v3.5.0

Minimized code

trait Bar[T]
given [T]: Bar[T] with {}
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {} //error

Output

(value : V) is not a valid singleton type, since it is not an immutable path
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {}

Expectation

The compiler should provide a hint to remove the inline keyword from the dependent value to resolve the error.

@soronpo soronpo added itype:bug area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages labels Sep 4, 2024
@soronpo
Copy link
Contributor Author

soronpo commented Sep 4, 2024

cc @Gedochao

@mbovel
Copy link
Member

mbovel commented Sep 23, 2024

Note for future readers: Nicolas explained why inline values cannot be stable paths in #16804 (comment).

What would you expect as a better error message? Something like the following?

(value : V) is not a valid singleton type, since it is not an immutable path.
Inline parameters are not considered immutable paths and cannot be used as
singleton types. Removing the `inline` qualifier from the `value` parameter
may help resolve this issue.

@mbovel
Copy link
Member

mbovel commented Sep 23, 2024

To solve this issue, I suggest to special-case the NotAPath message:

class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathID):
def msg(using Context) = i"$tp is not a valid $usage, since it is not an immutable path"
def explain(using Context) =
i"""An immutable path is
| - a reference to an immutable value, or
| - a reference to `this`, or
| - a selection of an immutable path with an immutable value."""

One can check if tp refers to a term symbol that is an inline parameter there, and display additional information if it is the case.

@soronpo
Copy link
Contributor Author

soronpo commented Sep 23, 2024

Note for future readers: Nicolas explained why inline values cannot be stable paths in #16804 (comment).

What would you expect as a better error message? Something like the following?

(value : V) is not a valid singleton type, since it is not an immutable path.
Inline parameters are not considered immutable paths and cannot be used as
singleton types. Removing the `inline` qualifier from the `value` parameter
may help resolve this issue.

Seems good. I think the compiler started to have a standardize a format for providing hints.
So it will look better with:

(value : V) is not a valid singleton type, since it is not an immutable path.
Inline parameters are not considered immutable paths and cannot be used as
singleton types. 

Hint: Removing the `inline` qualifier from the `value` parameter
may help resolve this issue.

@mbovel
Copy link
Member

mbovel commented Sep 23, 2024

This issue was picked for the Scala Issue Spree of tomorrow, September 24th. @HarrisL2, someone yet unknown and I will be working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants