Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 531d165

Browse files
committed
Properly print @use and @consume parameters
1 parent b867b3f commit 531d165

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

‎compiler/src/dotty/tools/dotc/core/Definitions.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ class Definitions {
11171117

11181118
// Set of annotations that are not printed in types except under -Yprint-debug
11191119
@tu lazy val SilentAnnots: Set[Symbol] =
1120-
Set(InlineParamAnnot, ErasedParamAnnot, RefineOverrideAnnot, SilentIntoAnnot)
1120+
Set(InlineParamAnnot, ErasedParamAnnot, RefineOverrideAnnot, SilentIntoAnnot, UseAnnot, ConsumeAnnot)
11211121

11221122
// A list of annotations that are commonly used to indicate that a field/method argument or return
11231123
// type is not null. These annotations are used by the nullification logic in JavaNullInterop to

‎compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
379379
protected def paramsText(lam: LambdaType): Text = {
380380
def paramText(ref: ParamRef) =
381381
val erased = ref.underlying.hasAnnotation(defn.ErasedParamAnnot)
382-
keywordText("erased ").provided(erased) ~ ParamRefNameString(ref) ~ hashStr(lam) ~ toTextRHS(ref.underlying, isParameter = true)
382+
def maybeAnnotsText(sym: ClassSymbol): Text =
383+
Str(s"@${sym.name}").provided(ref.underlying.hasAnnotation(sym))
384+
keywordText("erased ").provided(erased)
385+
~ maybeAnnotsText(defn.UseAnnot) ~ maybeAnnotsText(defn.ConsumeAnnot)
386+
~ ParamRefNameString(ref) ~ hashStr(lam) ~ toTextRHS(ref.underlying, isParameter = true)
383387
Text(lam.paramRefs.map(paramText), ", ")
384388
}
385389

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- [E164] Declaration Error: tests/neg-custom-args/captures/unbox-overrides.scala:8:6 ----------------------------------
22
8 | def foo(x: C): C // error
33
| ^
4-
|error overriding method foo in trait A of type (x: C): C;
4+
|error overriding method foo in trait A of type (@use x: C): C;
55
| method foo of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
66
|
77
| longer explanation available when compiling with `-explain`
88
-- [E164] Declaration Error: tests/neg-custom-args/captures/unbox-overrides.scala:9:6 ----------------------------------
99
9 | def bar(@use x: C): C // error
1010
| ^
1111
|error overriding method bar in trait A of type (x: C): C;
12-
| method bar of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
12+
| method bar of type (@use x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
1313
|
1414
| longer explanation available when compiling with `-explain`
1515
-- [E164] Declaration Error: tests/neg-custom-args/captures/unbox-overrides.scala:15:15 --------------------------------
1616
15 |abstract class C extends A[C], B2 // error
1717
| ^
18-
|error overriding method foo in trait A of type (x: C): C;
18+
|error overriding method foo in trait A of type (@use x: C): C;
1919
| method foo in trait B2 of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
2020
|
2121
| longer explanation available when compiling with `-explain`

‎tests/neg-custom-args/captures/unsound-reach-4.check‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
17 | def use(@consume x: F): File^ = x // error @consume override
1919
| ^
2020
| error overriding method use in trait Foo of type (x: File^): box File^;
21-
| method use of type (x: File^): File^2 has incompatible type
21+
| method use of type (@consume x: File^): File^2 has incompatible type
2222
|
2323
| where: ^ refers to the universal root capability
24-
| ^2 refers to a root capability associated with the result type of (x: File^): File^2
24+
| ^2 refers to a root capability associated with the result type of (@consume x: File^): File^2
2525
|
2626
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /