-
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.
feat: various features related to literal types (#657)
Closes partially #80 ### Summary of Changes * Show an error if literal types have no literals * Show an error if lists or maps are used in a literal types * Mark literal types as experimental (show a warning when they are used) * Compute type of manifest literal types * Evaluate literals to a literal type instead of the corresponding class. For example, the literal `1` now gets the type `literal<1>` instead of `Int`). --------- Co-authored-by: megalinter-bot <[email protected]>
1 parent
ca47870
commit 1775705
Showing
47 changed files
with
692 additions
and
171 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
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,60 @@ | ||
import { WorkspaceCache } from 'langium'; | ||
import { SafeDsServices } from '../safe-ds-module.js'; | ||
import { SafeDsClasses } from '../builtins/safe-ds-classes.js'; | ||
import { ClassType, Type, UnknownType } from './model.js'; | ||
import { SdsClass } from '../generated/ast.js'; | ||
|
||
export class SafeDsCoreTypes { | ||
private readonly builtinClasses: SafeDsClasses; | ||
private readonly cache: WorkspaceCache<string, Type>; | ||
|
||
constructor(services: SafeDsServices) { | ||
this.builtinClasses = services.builtins.Classes; | ||
this.cache = new WorkspaceCache(services.shared); | ||
} | ||
|
||
get AnyOrNull(): Type { | ||
return this.createCoreType(this.builtinClasses.Any, true); | ||
} | ||
|
||
get Boolean(): Type { | ||
return this.createCoreType(this.builtinClasses.Boolean); | ||
} | ||
|
||
get Float(): Type { | ||
return this.createCoreType(this.builtinClasses.Float); | ||
} | ||
|
||
get Int(): Type { | ||
return this.createCoreType(this.builtinClasses.Int); | ||
} | ||
|
||
get List(): Type { | ||
return this.createCoreType(this.builtinClasses.List); | ||
} | ||
|
||
get Map(): Type { | ||
return this.createCoreType(this.builtinClasses.Map); | ||
} | ||
|
||
/* c8 ignore start */ | ||
get NothingOrNull(): Type { | ||
return this.createCoreType(this.builtinClasses.Nothing, true); | ||
} | ||
/* c8 ignore stop */ | ||
|
||
get String(): Type { | ||
return this.createCoreType(this.builtinClasses.String); | ||
} | ||
|
||
private createCoreType(coreClass: SdsClass | undefined, isNullable: boolean = false): Type { | ||
/* c8 ignore start */ | ||
if (!coreClass) { | ||
return UnknownType; | ||
} | ||
/* c8 ignore stop */ | ||
|
||
const key = `${coreClass.name}~${isNullable}`; | ||
return this.cache.get(key, () => new ClassType(coreClass, isNullable)); | ||
} | ||
} |
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,204 @@ | ||
import { SafeDsServices } from '../safe-ds-module.js'; | ||
import { | ||
CallableType, | ||
ClassType, | ||
EnumType, | ||
EnumVariantType, | ||
LiteralType, | ||
NamedTupleType, | ||
StaticType, | ||
Type, | ||
UnionType, | ||
UnknownType, | ||
} from './model.js'; | ||
import { SafeDsClassHierarchy } from './safe-ds-class-hierarchy.js'; | ||
import { SdsDeclaration } from '../generated/ast.js'; | ||
import { | ||
BooleanConstant, | ||
Constant, | ||
FloatConstant, | ||
IntConstant, | ||
NullConstant, | ||
StringConstant, | ||
} from '../partialEvaluation/model.js'; | ||
import { SafeDsCoreTypes } from './safe-ds-core-types.js'; | ||
|
||
/* c8 ignore start */ | ||
export class SafeDsTypeChecker { | ||
private readonly classHierarchy: SafeDsClassHierarchy; | ||
private readonly coreTypes: SafeDsCoreTypes; | ||
|
||
constructor(services: SafeDsServices) { | ||
this.classHierarchy = services.types.ClassHierarchy; | ||
this.coreTypes = services.types.CoreTypes; | ||
} | ||
|
||
/** | ||
* Checks whether {@link type} is assignable {@link other}. | ||
*/ | ||
isAssignableTo(type: Type, other: Type): boolean { | ||
if (type instanceof CallableType) { | ||
return this.callableTypeIsAssignableTo(type, other); | ||
} else if (type instanceof ClassType) { | ||
return this.classTypeIsAssignableTo(type, other); | ||
} else if (type instanceof EnumType) { | ||
return this.enumTypeIsAssignableTo(type, other); | ||
} else if (type instanceof EnumVariantType) { | ||
return this.enumVariantTypeIsAssignableTo(type, other); | ||
} else if (type instanceof LiteralType) { | ||
return this.literalTypeIsAssignableTo(type, other); | ||
} else if (type instanceof NamedTupleType) { | ||
return this.namedTupleTypeIsAssignableTo(type, other); | ||
} else if (type instanceof StaticType) { | ||
return this.staticTypeIsAssignableTo(type, other); | ||
} else if (type instanceof UnionType) { | ||
return this.unionTypeIsAssignableTo(type, other); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private callableTypeIsAssignableTo(type: CallableType, other: Type): boolean { | ||
// return when (val unwrappedOther = unwrapVariadicType(other)) { | ||
// is CallableType -> { | ||
// // TODO: We need to compare names of parameters & results and can allow additional optional parameters | ||
// | ||
// // Sizes must match (too strict requirement -> should be loosened later) | ||
// if (this.parameters.size != unwrappedOther.parameters.size || this.results.size != this.results.size) { | ||
// return false | ||
// } | ||
// | ||
// // Actual parameters must be supertypes of expected parameters (contravariance) | ||
// this.parameters.zip(unwrappedOther.parameters).forEach { (thisParameter, otherParameter) -> | ||
// if (!otherParameter.isSubstitutableFor(thisParameter)) { | ||
// return false | ||
// } | ||
// } | ||
// | ||
// // Expected results must be subtypes of expected results (covariance) | ||
// this.results.zip(unwrappedOther.results).forEach { (thisResult, otherResult) -> | ||
// if (!thisResult.isSubstitutableFor(otherResult)) { | ||
// return false | ||
// } | ||
// } | ||
// | ||
// true | ||
// } | ||
// is ClassType -> { | ||
// unwrappedOther.sdsClass.qualifiedNameOrNull() == StdlibClasses.Any | ||
// } | ||
// is UnionType -> { | ||
// unwrappedOther.possibleTypes.any { this.isSubstitutableFor(it) } | ||
// } | ||
// else -> false | ||
// } | ||
// } | ||
|
||
return type.equals(other); | ||
} | ||
|
||
private classTypeIsAssignableTo(type: ClassType, other: Type): boolean { | ||
if (type.isNullable && !other.isNullable) { | ||
return false; | ||
} | ||
|
||
if (other instanceof ClassType) { | ||
return this.classHierarchy.isEqualToOrSubclassOf(type.declaration, other.declaration); | ||
} else if (other instanceof UnionType) { | ||
return other.possibleTypes.some((it) => this.isAssignableTo(type, it)); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private enumTypeIsAssignableTo(type: EnumType, other: Type): boolean { | ||
// return when (val unwrappedOther = unwrapVariadicType(other)) { | ||
// is ClassType -> { | ||
// (!this.isNullable || unwrappedOther.isNullable) && | ||
// unwrappedOther.sdsClass.qualifiedNameOrNull() == StdlibClasses.Any | ||
// } | ||
// is EnumType -> { | ||
// (!this.isNullable || unwrappedOther.isNullable) && this.sdsEnum == unwrappedOther.sdsEnum | ||
// } | ||
// is UnionType -> { | ||
// unwrappedOther.possibleTypes.any { this.isSubstitutableFor(it) } | ||
// } | ||
// else -> false | ||
// } | ||
|
||
return type.equals(other); | ||
} | ||
|
||
private enumVariantTypeIsAssignableTo(type: EnumVariantType, other: Type): boolean { | ||
// return when (val unwrappedOther = unwrapVariadicType(other)) { | ||
// is ClassType -> { | ||
// (!this.isNullable || unwrappedOther.isNullable) && | ||
// unwrappedOther.sdsClass.qualifiedNameOrNull() == StdlibClasses.Any | ||
// } | ||
// is EnumType -> { | ||
// (!this.isNullable || unwrappedOther.isNullable) && | ||
// this.sdsEnumVariant in unwrappedOther.sdsEnum.variantsOrEmpty() | ||
// } | ||
// is EnumVariantType -> { | ||
// (!this.isNullable || unwrappedOther.isNullable) && this.sdsEnumVariant == unwrappedOther.sdsEnumVariant | ||
// } | ||
// is UnionType -> unwrappedOther.possibleTypes.any { this.isSubstitutableFor(it) } | ||
// else -> false | ||
// } | ||
|
||
return type.equals(other); | ||
} | ||
|
||
private literalTypeIsAssignableTo(type: LiteralType, other: Type): boolean { | ||
if (type.isNullable && !other.isNullable) { | ||
return false; | ||
} | ||
|
||
if (other instanceof ClassType) { | ||
if (other.equals(this.coreTypes.AnyOrNull)) { | ||
return true; | ||
} | ||
|
||
return type.constants.every((constant) => { | ||
const constantType = this.constantToType(constant); | ||
return this.isAssignableTo(constantType, other); | ||
}); | ||
} else if (other instanceof LiteralType) { | ||
return type.constants.every((constant) => | ||
other.constants.some((otherConstant) => constant.equals(otherConstant)), | ||
); | ||
} else { | ||
// TODO: union type | ||
return false; | ||
} | ||
} | ||
|
||
private constantToType(constant: Constant): Type { | ||
if (constant instanceof BooleanConstant) { | ||
return this.coreTypes.Boolean; | ||
} else if (constant instanceof FloatConstant) { | ||
return this.coreTypes.Float; | ||
} else if (constant instanceof IntConstant) { | ||
return this.coreTypes.Int; | ||
} else if (constant === NullConstant) { | ||
return this.coreTypes.NothingOrNull; | ||
} else if (constant instanceof StringConstant) { | ||
return this.coreTypes.String; | ||
} else { | ||
return UnknownType; | ||
} | ||
} | ||
|
||
private namedTupleTypeIsAssignableTo(type: NamedTupleType<SdsDeclaration>, other: Type): boolean { | ||
return type.equals(other); | ||
} | ||
|
||
private staticTypeIsAssignableTo(type: Type, other: Type): boolean { | ||
return type.equals(other); | ||
} | ||
|
||
private unionTypeIsAssignableTo(type: UnionType, other: Type): boolean { | ||
return type.equals(other); | ||
} | ||
} | ||
/* c8 ignore stop */ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { isSdsList, isSdsMap, SdsLiteralType } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { literalsOrEmpty } from '../../../helpers/nodeProperties.js'; | ||
import { isEmpty } from 'radash'; | ||
|
||
export const CODE_UNION_TYPE_MISSING_LITERALS = 'union-type/missing-literals'; | ||
export const CODE_LITERAL_TYPE_LIST_LITERAL = 'literal-type/list-literal'; | ||
export const CODE_LITERAL_TYPE_MAP_LITERAL = 'literal-type/map-literal'; | ||
|
||
export const literalTypeMustHaveLiterals = (node: SdsLiteralType, accept: ValidationAcceptor): void => { | ||
if (isEmpty(literalsOrEmpty(node))) { | ||
accept('error', 'A literal type must have at least one literal.', { | ||
node, | ||
property: 'literalList', | ||
code: CODE_UNION_TYPE_MISSING_LITERALS, | ||
}); | ||
} | ||
}; | ||
|
||
export const literalTypeMustNotContainListLiteral = (node: SdsLiteralType, accept: ValidationAcceptor): void => { | ||
for (const literal of literalsOrEmpty(node)) { | ||
if (isSdsList(literal)) { | ||
accept('error', 'Literal types must not contain list literals.', { | ||
node: literal, | ||
code: CODE_LITERAL_TYPE_LIST_LITERAL, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
export const literalTypeMustNotContainMapLiteral = (node: SdsLiteralType, accept: ValidationAcceptor): void => { | ||
for (const literal of literalsOrEmpty(node)) { | ||
if (isSdsMap(literal)) { | ||
accept('error', 'Literal types must not contain map literals.', { | ||
node: literal, | ||
code: CODE_LITERAL_TYPE_MAP_LITERAL, | ||
}); | ||
} | ||
} | ||
}; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
tests/resources/grammar/types/literal types/bad-no literal list.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 @@ | ||
// $TEST$ syntax_error | ||
|
||
segment mySegment( | ||
x: literal | ||
) {} |
5 changes: 5 additions & 0 deletions
5
tests/resources/grammar/types/literal types/good-with list literal.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 @@ | ||
// $TEST$ no_syntax_error | ||
|
||
segment mySegment( | ||
x: literal<[]> | ||
) {} |
5 changes: 5 additions & 0 deletions
5
tests/resources/grammar/types/literal types/good-with map literal.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 @@ | ||
// $TEST$ no_syntax_error | ||
|
||
segment mySegment( | ||
x: literal<{}> | ||
) {} |
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
6 changes: 4 additions & 2 deletions
6
tests/resources/typing/expressions/block lambdas/that are isolated/main.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,13 +1,15 @@ | ||
package tests.typing.expressions.blockLambdas.thatAreIsolated | ||
|
||
fun g() -> r: Int | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization (p: $Unknown) -> (r: Int, s: $Unknown) | ||
// $TEST$ serialization (p: $Unknown) -> (r: literal<1>, s: $Unknown) | ||
»(p) { | ||
yield r, yield s = 1; | ||
}«; | ||
|
||
// $TEST$ serialization (p: $Unknown) -> (r: Int, s: $Unknown) | ||
val f = »(p) { | ||
yield r, yield s = 1; | ||
yield r, yield s = g(); | ||
}«; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
tests/resources/typing/expressions/block lambdas/with manifest types/main.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
4 changes: 2 additions & 2 deletions
4
tests/resources/typing/expressions/calls/of block lambdas/main.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
2 changes: 1 addition & 1 deletion
2
tests/resources/typing/expressions/calls/of expression lambdas/main.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,6 +1,6 @@ | ||
package tests.typing.expressions.calls.ofExpressionLambdas | ||
|
||
pipeline myPipeline { | ||
// $TEST$ serialization Int | ||
// $TEST$ serialization literal<1> | ||
»(() -> 1)()«; | ||
} |
6 changes: 4 additions & 2 deletions
6
tests/resources/typing/expressions/expression lambdas/that are isolated/main.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,9 +1,11 @@ | ||
package tests.typing.expressions.expressionLambdas.thatAreIsolated | ||
|
||
fun g() -> r: Int | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization (p: $Unknown) -> (result: Int) | ||
»(p) -> 1«; | ||
»(p) -> g()«; | ||
|
||
// $TEST$ serialization (p: $Unknown) -> (result: Int) | ||
// $TEST$ serialization (p: $Unknown) -> (result: literal<1>) | ||
val f = »(p) -> 1«; | ||
} |
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
8 changes: 4 additions & 4 deletions
8
tests/resources/typing/expressions/expression lambdas/that are yielded/main.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,16 +1,16 @@ | ||
package tests.typing.expressions.expressionLambdas.thatAreYielded | ||
|
||
segment mySegment() -> ( | ||
r: (p: String) -> (), | ||
r: (p: String) -> (r: Int), | ||
s: () -> (), | ||
t: Int, | ||
) { | ||
// $TEST$ serialization (p: String) -> (result: Int) | ||
// $TEST$ serialization (p: String) -> (result: literal<1>) | ||
yield r = »(p) -> 1«; | ||
|
||
// $TEST$ serialization (p: $Unknown) -> (result: Int) | ||
// $TEST$ serialization (p: $Unknown) -> (result: literal<1>) | ||
yield s = »(p) -> 1«; | ||
|
||
// $TEST$ serialization (p: $Unknown) -> (result: Int) | ||
// $TEST$ serialization (p: $Unknown) -> (result: literal<1>) | ||
yield t = »(p) -> 1«; | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/resources/typing/expressions/expression lambdas/with manifest types/main.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,6 +1,6 @@ | ||
package tests.typing.expressions.expressionLambdas.withManifestTypes | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization (p: Int) -> (result: Int) | ||
// $TEST$ serialization (p: Int) -> (result: literal<1>) | ||
»(p: Int) -> 1«; | ||
} |
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
100 changes: 84 additions & 16 deletions
100
tests/resources/typing/expressions/operations/arithmetic/main.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,36 +1,104 @@ | ||
package tests.typing.operations.arithmetic | ||
|
||
pipeline myPipeline { | ||
// $TEST$ serialization Int | ||
fun anyInt() -> r: Int | ||
fun anyFloat() -> r: Float | ||
|
||
pipeline constantOperands { | ||
// $TEST$ serialization literal<2> | ||
val additionIntInt = »1 + 1«; | ||
// $TEST$ serialization Int | ||
// $TEST$ serialization literal<0> | ||
val subtractionIntInt = »1 - 1«; | ||
// $TEST$ serialization Int | ||
// $TEST$ serialization literal<1> | ||
val multiplicationIntInt = »1 * 1«; | ||
// $TEST$ serialization Int | ||
// $TEST$ serialization literal<1> | ||
val divisionIntInt = »1 / 1«; | ||
// $TEST$ serialization Int | ||
|
||
// $TEST$ serialization literal<2.5> | ||
val additionIntFloat = »1 + 1.5«; | ||
// $TEST$ serialization literal<-0.5> | ||
val subtractionIntFloat = »1 - 1.5«; | ||
// $TEST$ serialization literal<1.5> | ||
val multiplicationIntFloat = »1 * 1.5«; | ||
// $TEST$ serialization literal<1.6> | ||
val divisionIntFloat = »1 / 0.625«; | ||
|
||
// $TEST$ serialization literal<2.5> | ||
val additionFloatInt = »1.5 + 1«; | ||
// $TEST$ serialization literal<0.5> | ||
val subtractionFloatInt = »1.5 - 1«; | ||
// $TEST$ serialization literal<1.5> | ||
val multiplicationFloatInt = »1.5 * 1«; | ||
// $TEST$ serialization literal<1.5> | ||
val divisionFloatInt = »1.5 / 1«; | ||
|
||
// $TEST$ serialization literal<2.75> | ||
val additionFloatFloat = »1.5 + 1.25«; | ||
// $TEST$ serialization literal<0.25> | ||
val subtractionFloatFloat = »1.5 - 1.25«; | ||
// $TEST$ serialization literal<1.875> | ||
val multiplicationFloatFloat = »1.5 * 1.25«; | ||
// $TEST$ serialization literal<0.6> | ||
val divisionFloatFloat = »1.5 / 2.5«; | ||
|
||
// $TEST$ serialization literal<-1> | ||
val negationInt = »-1«; | ||
// $TEST$ serialization literal<-1.5> | ||
val negationFloat = »-1.5«; | ||
} | ||
|
||
pipeline invalidOperands { | ||
// $TEST$ serialization Float | ||
val additionInvalid = »true + true«; | ||
// $TEST$ serialization Float | ||
val subtractionInvalid = »true - true«; | ||
// $TEST$ serialization Float | ||
val multiplicationInvalid = »true * true«; | ||
// $TEST$ serialization Float | ||
val divisionInvalid = »true / true«; | ||
|
||
// $TEST$ serialization Float | ||
val additionIntFloat = »1 + 1.0«; | ||
val negationInvalid = »-true«; | ||
} | ||
|
||
pipeline nonConstantOperands { | ||
// $TEST$ serialization Int | ||
val additionIntInt = »anyInt() + anyInt()«; | ||
// $TEST$ serialization Int | ||
val subtractionIntInt = »anyInt() - anyInt()«; | ||
// $TEST$ serialization Int | ||
val multiplicationIntInt = »anyInt() * anyInt()«; | ||
// $TEST$ serialization Int | ||
val divisionIntInt = »anyInt() / anyInt()«; | ||
|
||
// $TEST$ serialization Float | ||
val subtractionIntFloat = »1 - 1.0«; | ||
val additionIntFloat = »anyInt() + anyFloat()«; | ||
// $TEST$ serialization Float | ||
val multiplicationIntFloat = »1 * 1.0«; | ||
val subtractionIntFloat = »anyInt() - anyFloat()«; | ||
// $TEST$ serialization Float | ||
val divisionIntFloat = »1 / 1.0«; | ||
val multiplicationIntFloat = »anyInt() * anyFloat()«; | ||
// $TEST$ serialization Float | ||
val negationFloat = »-1.0«; | ||
val divisionIntFloat = »anyInt() / anyFloat()«; | ||
|
||
// $TEST$ serialization Float | ||
val additionInvalid = »true + true«; | ||
val additionFloatInt = »anyFloat() + anyInt()«; | ||
// $TEST$ serialization Float | ||
val subtractionInvalid = »true - true«; | ||
val subtractionFloatInt = »anyFloat() - anyInt()«; | ||
// $TEST$ serialization Float | ||
val multiplicationInvalid = »true * true«; | ||
val multiplicationFloatInt = »anyFloat() * anyInt()«; | ||
// $TEST$ serialization Float | ||
val divisionInvalid = »true / true«; | ||
val divisionFloatInt = »anyFloat() / anyInt()«; | ||
|
||
// $TEST$ serialization Float | ||
val negationInvalid = »-true«; | ||
val additionFloatFloat = »anyFloat() + anyFloat()«; | ||
// $TEST$ serialization Float | ||
val subtractionFloatFloat = »anyFloat() - anyFloat()«; | ||
// $TEST$ serialization Float | ||
val multiplicationFloatFloat = »anyFloat() * anyFloat()«; | ||
// $TEST$ serialization Float | ||
val divisionFloatFloat = »anyFloat() / anyFloat()«; | ||
|
||
// $TEST$ serialization Int | ||
val negationInt = »-anyInt()«; | ||
// $TEST$ serialization Float | ||
val negationFloat = »-anyFloat()«; | ||
} |
8 changes: 4 additions & 4 deletions
8
tests/resources/typing/expressions/operations/comparison/main.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
17 changes: 13 additions & 4 deletions
17
tests/resources/typing/expressions/operations/equality/main.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,13 +1,22 @@ | ||
package tests.typing.operations.equality | ||
|
||
pipeline myPipeline { | ||
// $TEST$ serialization Boolean | ||
// $TEST$ serialization literal<true> | ||
val equals = (»1 == 1«); | ||
// $TEST$ serialization Boolean | ||
// $TEST$ serialization literal<false> | ||
val notEquals = (»1 != 1«); | ||
|
||
// $TEST$ serialization literal<true> | ||
val identicalTo = (»1 === 1«); | ||
// $TEST$ serialization literal<false> | ||
val notIdenticalTo = (»1 !== 1«); | ||
|
||
// $TEST$ serialization Boolean | ||
val nonConstantEquals = (»1 == unresolved«); | ||
// $TEST$ serialization Boolean | ||
val nonConstantNotEquals = (»1 != unresolved«); | ||
// $TEST$ serialization Boolean | ||
val strictlyEquals = (»1 === 1«); | ||
val nonConstantIdenticalTo = (»1 === unresolved«); | ||
// $TEST$ serialization Boolean | ||
val notStrictlyEquals = (»1 !== 1«); | ||
val nonConstantNotIdenticalTo = (»1 !== unresolved«); | ||
} |
6 changes: 3 additions & 3 deletions
6
tests/resources/typing/expressions/operations/logical/main.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
5 changes: 4 additions & 1 deletion
5
tests/resources/typing/expressions/template strings/main.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,6 +1,9 @@ | ||
package tests.typing.expressions.templateStrings | ||
|
||
pipeline myPipeline { | ||
// $TEST$ serialization literal<"1 + 2 = 3"> | ||
val valid = »"1 + 2 = {{ 1 + 2 }}"«; | ||
|
||
// $TEST$ serialization String | ||
val templateString = »"1 + 2 = {{ 1 + 2 }}"«; | ||
val invalid = »"1 + 2 = {{ unresolved }}"«; | ||
} |
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,10 @@ | ||
package tests.typing.types.literalTypes | ||
|
||
// $TEST$ serialization literal<> | ||
fun myFunction1(f: »literal<>«) | ||
|
||
// $TEST$ serialization literal<1, 2> | ||
fun myFunction2(f: »literal<1, 2>«) | ||
|
||
// $TEST$ serialization literal<1, ""> | ||
fun myFunction3(f: »literal<1, "">«) |
6 changes: 6 additions & 0 deletions
6
tests/resources/validation/experimental language feature/literal types/main.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,6 @@ | ||
package tests.validation.experimentalLanguageFeature.literalTypes | ||
|
||
fun myFunction( | ||
// $TEST$ warning "Literal types are experimental and may change without prior notice." | ||
p: »literal<>« | ||
) |
16 changes: 16 additions & 0 deletions
16
tests/resources/validation/other/types/literal types/must have literals/main.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,16 @@ | ||
package tests.validation.other.types.literalTypes.mustHaveLiterals | ||
|
||
// $TEST$ error "A literal type must have at least one literal." | ||
segment mySegment1( | ||
p: literal»<>« | ||
) {} | ||
|
||
// $TEST$ no error "A literal type must have at least one literal." | ||
segment mySegment2( | ||
p: literal»<1>« | ||
) {} | ||
|
||
// $TEST$ no error "A literal type must have at least one literal." | ||
segment mySegment3( | ||
p: literal»<1, "">« | ||
) {} |
6 changes: 6 additions & 0 deletions
6
...esources/validation/other/types/literal types/must not contain list literals/main.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,6 @@ | ||
package tests.validation.other.types.literalTypes.mustNotContanListLiterals | ||
|
||
// $TEST$ error "Literal types must not contain list literals." | ||
segment mySegment( | ||
x: literal<»[]«> | ||
) {} |
6 changes: 6 additions & 0 deletions
6
...resources/validation/other/types/literal types/must not contain map literals/main.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,6 @@ | ||
package tests.validation.other.types.literalsTypes.mustNotContainMapLiterals | ||
|
||
// $TEST$ error "Literal types must not contain map literals." | ||
segment mySegment( | ||
x: literal<»{}«> | ||
) {} |
6 changes: 3 additions & 3 deletions
6
tests/resources/validation/other/types/union types/must have type arguments/main.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,16 +1,16 @@ | ||
package tests.validation.other.types.unionTypes.mustHaveTypeArguments | ||
|
||
// $TEST$ error "A union type must have least one type argument." | ||
// $TEST$ error "A union type must have at least one type argument." | ||
segment mySegment1( | ||
p: union»<>« | ||
) {} | ||
|
||
// $TEST$ no error "A union type must have least one type argument." | ||
// $TEST$ no error "A union type must have at least one type argument." | ||
segment mySegment2( | ||
p: union»<Int>« | ||
) {} | ||
|
||
// $TEST$ no error "A union type must have least one type argument." | ||
// $TEST$ no error "A union type must have at least one type argument." | ||
segment mySegment3( | ||
p: union»<Int, Float>« | ||
) {} |