-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #558 ### Summary of Changes Add a `const` modifier for parameters to indicate that they only accept values that can be evaluated to a constant expression at compile-time. This replaces the original `@Constant` annotation. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
- Loading branch information
1 parent
bf20c7c
commit ea4a9ba
Showing
255 changed files
with
2,477 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SdsAnnotation } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { parametersOrEmpty } from '../../../helpers/nodeProperties.js'; | ||
|
||
export const CODE_ANNOTATION_PARAMETER_CONST_MODIFIER = 'annotation/parameter-const-modifier'; | ||
|
||
export const annotationParameterShouldNotHaveConstModifier = (node: SdsAnnotation, accept: ValidationAcceptor) => { | ||
for (const parameter of parametersOrEmpty(node)) { | ||
if (parameter.isConstant) { | ||
accept('info', 'Parameters of annotations implicitly have the const modifier.', { | ||
node: parameter, | ||
property: 'name', | ||
code: CODE_ANNOTATION_PARAMETER_CONST_MODIFIER, | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SdsLambda } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { parametersOrEmpty } from '../../../helpers/nodeProperties.js'; | ||
|
||
export const CODE_LAMBDA_CONST_MODIFIER = 'lambda/const-modifier'; | ||
|
||
export const lambdaParameterMustNotHaveConstModifier = (node: SdsLambda, accept: ValidationAcceptor): void => { | ||
for (const parameter of parametersOrEmpty(node)) { | ||
if (parameter.isConstant) { | ||
accept('error', 'The const modifier is not applicable to parameters of lambdas.', { | ||
node: parameter, | ||
property: 'name', | ||
code: CODE_LAMBDA_CONST_MODIFIER, | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 56 additions & 16 deletions
72
tests/resources/formatting/declarations/annotations/multiple parameters.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,73 @@ | ||
annotation MyAnnotation ( | ||
|
||
@Annotation a , | ||
@Annotation a1 , | ||
|
||
b = 0 , | ||
b1 = 0 , | ||
|
||
vararg c , | ||
vararg c1 , | ||
|
||
vararg d : Int = 1 , | ||
vararg d1 : Int = 1 , | ||
|
||
e : Int , | ||
e1 : Int , | ||
|
||
f : Int = 2 , | ||
f1 : Int = 2 , | ||
|
||
vararg g : Int , | ||
vararg g1 : Int , | ||
|
||
vararg h : Int = 3 | ||
vararg h1 : Int = 3 , | ||
|
||
@Annotation const a2 , | ||
|
||
const b2 = 0 , | ||
|
||
const vararg c2 , | ||
|
||
const vararg d2 : Int = 1 , | ||
|
||
const e2 : Int , | ||
|
||
const f2 : Int = 2 , | ||
|
||
const vararg g2 : Int , | ||
|
||
const vararg h2 : Int = 3 , | ||
|
||
@Annotation vararg const a3 , | ||
|
||
vararg const c3 , | ||
|
||
vararg const d3 : Int = 1 , | ||
|
||
vararg const g3 : Int , | ||
|
||
vararg const h3 : Int = 3 | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation( | ||
@Annotation | ||
a, | ||
b = 0, | ||
vararg c, | ||
vararg d: Int = 1, | ||
e: Int, | ||
f: Int = 2, | ||
vararg g: Int, | ||
vararg h: Int = 3 | ||
a1, | ||
b1 = 0, | ||
vararg c1, | ||
vararg d1: Int = 1, | ||
e1: Int, | ||
f1: Int = 2, | ||
vararg g1: Int, | ||
vararg h1: Int = 3, | ||
@Annotation | ||
const a2, | ||
const b2 = 0, | ||
const vararg c2, | ||
const vararg d2: Int = 1, | ||
const e2: Int, | ||
const f2: Int = 2, | ||
const vararg g2: Int, | ||
const vararg h2: Int = 3, | ||
@Annotation | ||
vararg const a3, | ||
vararg const c3, | ||
vararg const d3: Int = 1, | ||
vararg const g3: Int, | ||
vararg const h3: Int = 3 | ||
) |
5 changes: 5 additions & 0 deletions
5
...resources/formatting/declarations/annotations/with const typed optional parameter.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
annotation MyAnnotation ( const a : Int = 1 ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation(const a: Int = 1) |
5 changes: 5 additions & 0 deletions
5
...resources/formatting/declarations/annotations/with const typed required parameter.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
annotation MyAnnotation ( const a : Int ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation(const a: Int) |
9 changes: 9 additions & 0 deletions
9
...declarations/annotations/with const typed variadic parameter (with default value).sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
annotation MyAnnotation1 ( const vararg a : Int = 1 ) | ||
|
||
annotation MyAnnotation2 ( vararg const a : Int = 1 ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation1(const vararg a: Int = 1) | ||
|
||
annotation MyAnnotation2(vararg const a: Int = 1) |
9 changes: 9 additions & 0 deletions
9
...resources/formatting/declarations/annotations/with const typed variadic parameter.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
annotation MyAnnotation1 ( const vararg a : Int ) | ||
|
||
annotation MyAnnotation2 ( vararg const a : Int ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation1(const vararg a: Int) | ||
|
||
annotation MyAnnotation2(vararg const a: Int) |
5 changes: 5 additions & 0 deletions
5
...sources/formatting/declarations/annotations/with const untyped optional parameter.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
annotation MyAnnotation ( const a = 1 ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation(const a = 1) |
5 changes: 5 additions & 0 deletions
5
...sources/formatting/declarations/annotations/with const untyped required parameter.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
annotation MyAnnotation ( const a ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation(const a) |
9 changes: 9 additions & 0 deletions
9
...clarations/annotations/with const untyped variadic parameter (with default value).sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
annotation MyAnnotation1 ( const vararg a = 1 ) | ||
|
||
annotation MyAnnotation2 ( vararg const a = 1 ) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
annotation MyAnnotation1(const vararg a = 1) | ||
|
||
annotation MyAnnotation2(vararg const a = 1) |
Oops, something went wrong.