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

Add better error reporting for inlined non-immutable paths #21639

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1817,13 +1817,25 @@ class SuperCallsNotAllowedInlineable(symbol: Symbol)(using Context)
}

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 msg(using Context) = i"$tp is not a valid $usage, since it is not an immutable path" + inlineParamAddendum
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."""

def inlineParamAddendum(using Context) =
val sym = tp.termSymbol
if sym.isAllOf(Flags.InlineParam) then
i"""
|Inline parameters are not considered immutable paths and cannot be used as
|singleton types.
|
|Hint: Removing the `inline` qualifier from the `${sym.name}` parameter
|may help resolve this issue."""
else ""


class WrongNumberOfParameters(tree: untpd.Tree, foundCount: Int, pt: Type, expectedCount: Int)(using Context)
extends SyntaxMsg(WrongNumberOfParametersID) {
def msg(using Context) = s"Wrong number of parameters, expected: $expectedCount"
Expand Down
11 changes: 11 additions & 0 deletions tests/neg/21538.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- [E083] Type Error: tests/neg/21538.scala:3:45 -----------------------------------------------------------------------
3 |inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {} // error
| ^^^^^^^^^^
| (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.
|
| longer explanation available when compiling with `-explain`
3 changes: 3 additions & 0 deletions tests/neg/21538.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait Bar[T]
given [T]: Bar[T] with {}
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {} // error
Loading