-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Document Scala compiler error codes #24734
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
base: main
Are you sure you want to change the base?
Conversation
|
is there an automated process to check for addition of new error codes? |
Not yet but I'll add one |
|
We could also link to these pages from DiagnosticRelatedInformation, it's available in the sbt interfaces. |
|
Ach, no that would have to be another field, which is not exposed here :/ |
|
We could anyway link the codes in metals automatically once this is merged, which will work on all Scala 3 versions |
#24755) Extracted from #24734 Adds support for `sc-opts:` attribute that can be set in Markdown code snippets, allowing to pass additioanl arguments to snippet compiler. This would allow us in #24734 to correctlly document behaviour of snippets producing error codes that require additional compiler options to be activated. Example: ensure that `-Werror` makes given code to actually fail which can be checked with `sc:fail`, ``` ```scala sc:fail sc-opts:-Werror,-explain def exampleShouldError(input: Option[String]): Unit = input match case Some("foo") => ??? ```. ```
…om messages.scala
…erateReferenceDocumentation` (crashed)
… repl, tasty-inspector, staging, etc.
b76b889 to
e3f3f86
Compare
| on any expected exceptions. For example: | ||
|
|
||
| ```scala | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we recoment braceless syntax in these snippets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of example for other error codes use bracless syntax, I can adjust this one.
| ``` | ||
|
|
||
| It is recommended to use the `NonFatal` extractor to catch all exceptions as it | ||
| correctly handles transfer functions like `return`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need an example? What is transfer function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, example and description was generated based on -explain description from compiler.
So in fact here we have a duplication, the same example in explain and in description (altough outputs are allowed to change any moment)
|
Review recommendation - here's the list of error codes that are not tested in snippets: These error code are most likely to be invalid, as we couldn't create an exmaple of code snippet which would produce them. Additional care should be taken against inactive error codes (based on definitions in ErrorMessageId, or by listing error-codes having
Total: 18 inactive error codes Or other code snippets are validated to ensure that it's possible to produce a described error code. Some additional care can be also made towards |
|
|
||
| This error is emitted when an expression has a different type than what is expected in that context. | ||
|
|
||
| The compiler found an expression of one type where a different type was expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to repeat the information above.
|
|
||
| This error is emitted when trying to access a member (method, field, or type) that does not exist on the given type. | ||
|
|
||
| The compiler cannot find a member with the specified name on the given type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The compiler cannot find a member with the specified name on the given type. |
|
|
||
| This error is emitted when a `case class` is defined with the `implicit` modifier. Case classes cannot be implicit in Scala. | ||
|
|
||
| Implicit classes may not be case classes. Case classes automatically generate companion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Implicit classes may not be case classes. Case classes automatically generate companion | |
| Case classes automatically generate companion |
|
|
||
| This error is emitted when an implicit class has more than one non-implicit parameter in its primary constructor. Implicit classes must accept exactly one primary constructor parameter. | ||
|
|
||
| Implicit classes may only take one non-implicit argument in their constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Implicit classes may only take one non-implicit argument in their constructor. |
| This error is emitted when the same modifier is specified more than once on a definition. | ||
|
|
||
| This happens when you accidentally specify the same modifier twice on a definition. | ||
| Each modifier should only appear once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This error is emitted when the same modifier is specified more than once on a definition. | |
| This happens when you accidentally specify the same modifier twice on a definition. | |
| Each modifier should only appear once. | |
| This error is emitted when the same modifier is specified more than once on a definition. | |
| Each modifier should only appear once. |
| This error is emitted when the underscore (`_`) placeholder syntax is used in a context where it cannot be bound to a parameter. | ||
|
|
||
| The `_` placeholder syntax was used where it could not be bound. | ||
| Consider explicitly writing the variable binding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This error is emitted when the underscore (`_`) placeholder syntax is used in a context where it cannot be bound to a parameter. | |
| The `_` placeholder syntax was used where it could not be bound. | |
| Consider explicitly writing the variable binding. | |
| This error is emitted when the underscore (`_`) placeholder syntax is used in a context where it cannot be bound to a parameter. | |
| Consider explicitly writing the variable binding. |
| This error is emitted when an abstract method declaration is missing its return type. Abstract declarations must have explicit return types. | ||
|
|
||
| An abstract declaration must have a return type. Without a body, the compiler | ||
| cannot infer the type of the method, so it must be explicitly specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This error is emitted when an abstract method declaration is missing its return type. Abstract declarations must have explicit return types. | |
| An abstract declaration must have a return type. Without a body, the compiler | |
| cannot infer the type of the method, so it must be explicitly specified. | |
| This error is emitted when an abstract method declaration is missing its return type. Abstract declarations must have explicit return types. Without a body, the compiler | |
| cannot infer the type of the method, so it must be explicitly specified. |
|
|
||
| This error is emitted when a variable binding is used in a pattern alternative (`|`). Variables are not allowed in alternative patterns. | ||
|
|
||
| Variables are not allowed within alternate pattern matches. When you use the `|` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Variables are not allowed within alternate pattern matches. When you use the `|` | |
| When you use the `|` |
| @@ -0,0 +1,17 @@ | |||
| --- | |||
| title: E025: Identifier Expected | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shows up in
object obj2:
val a: this = ???
tgodzik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a look to the errors up to 50
| This error is emitted when the parser expects an identifier but finds something else, typically when an invalid token is used where a name is required. | ||
|
|
||
| The compiler message states: **"identifier expected"** | ||
|
|
||
| This can occur when: | ||
| - An invalid token is used where an identifier is expected | ||
| - A type annotation uses something that is not a valid identifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This error is emitted when the parser expects an identifier but finds something else, typically when an invalid token is used where a name is required. | |
| The compiler message states: **"identifier expected"** | |
| This can occur when: | |
| - An invalid token is used where an identifier is expected | |
| - A type annotation uses something that is not a valid identifier | |
| This error is emitted when the parser expects an identifier but finds something else, typically when an invalid token is used where a name is required. | |
| The compiler message states: **"identifier expected"** | |
| This can occur when for example when a type annotation uses something that is not a valid identifier |
otherwise we repeat the above
|
|
||
| This restriction exists because varargs can accept zero or more arguments at runtime, so having additional parameters after it would make the call syntax ambiguous. | ||
|
|
||
| **Note:** This error code is active in the compiler and is triggered during parsing when validating parameter lists. The exact syntax to reproduce this error in modern Scala 3 requires further investigation, as the parser may produce different errors for malformed parameter lists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we should connect this code to
| syntaxError(em"spread operator `*` not allowed here; must come last in a parameter list") |
| @@ -0,0 +1,21 @@ | |||
| --- | |||
| title: E028: Illegal Literal | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one looks dead, I think it's mostly just in case.
|
|
||
| This error is emitted when the wildcard type syntax (`_` or `?`) is used in a position where it cannot be bound to a concrete type. | ||
|
|
||
| The wildcard type syntax was used where it could not be bound. Replace the wildcard with a non-wildcard type. If the type doesn't matter, try replacing the wildcard with `Any`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The wildcard type syntax was used where it could not be bound. Replace the wildcard with a non-wildcard type. If the type doesn't matter, try replacing the wildcard with `Any`. | |
| Replace the wildcard with a non-wildcard type. If the type doesn't matter, try replacing the wildcard with `Any`. |
| title: E047: Cyclic Reference Involving Implicit | ||
| kind: Error | ||
| --- | ||
| # E047: Cyclic Reference Involving Implicit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be another hail mary error -> it might happen, but in a last ditch scenario


Resolves #24720
All identified error codes produced by compiler are now documented in the reference docs.
-explain), and examples how to fix given problem.scala -S 3.nightly test --with-compiler project/scripts/checkErrorCodeSnippets.test.scala -- +a +l +cIt validates that all error codes (unless explicitlly excluded) are well defined: has example snippet, output errors and solutions. This might also check for additional attributes, eg. :
untiltag for inactive codes containg the last version when given error code was emmitedsincetag for code introduced after 3.0.0 - first stable version when given error is emmitedscala3-compiler, this allows to test changes for manually published versions of the compiler, by providing explicit-S <versionwe can test against any version of the compiler, including locally published ones.Piggy backs fixes that would be required to have correct assertions in generated scaladoc (would be most likelly cherry-picked before merge): - allow to specific `sc-opts:*` to pass specify scalacOptions that would be passed to the snippetCompiler - show position of snippets that failed to compileThe changes above were extracted to #24755
Piggy backed changes:
scaladoc/generateReferenceDocumentationstarted to crash after addition of first Markdown snippet - it was caused by classpath/scaladoc setting issue. The problem was fixed, by removing no longer required__fake__.scalafile which was used in Scala 3.1 and earlier to workaround requirement of having at least 1 Scala source.Documentation itself was generated using LLM agents and requires manual review - mostly for correctness of descriptions, code snippets itself are validated to produce correct error codes unless marked with
sc:nocompile(see list of non-reproductible error codes in created tool).Here's the gist with context used to instrument agents