Skip to content

Commit

Permalink
test: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Nov 4, 2023
1 parent 35a90a6 commit 67f3348
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ export class SafeDsTypeChecker {
const typeEntry = type.outputType.entries[i];
const otherEntry = other.outputType.entries[i];

// Names must match
if (typeEntry.name !== otherEntry.name) {
return false;
}
// Names must not match since we always fetch results by index

// Types must be covariant
if (!this.isAssignableTo(typeEntry.type, otherEntry.type)) {
Expand Down
8 changes: 6 additions & 2 deletions packages/safe-ds-lang/src/language/validation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => {

export const indexedAccessReceiverMustBeListOrMap = (services: SafeDsServices) => {
const coreTypes = services.types.CoreTypes;
const typeChecker = services.types.TypeChecker;
const typeComputer = services.types.TypeComputer;

return (node: SdsIndexedAccess, accept: ValidationAcceptor): void => {
const receiverType = typeComputer.computeType(node.receiver);
if (receiverType !== coreTypes.List && receiverType !== coreTypes.Map) {
if (
!typeChecker.isAssignableTo(receiverType, coreTypes.List) &&
!typeChecker.isAssignableTo(receiverType, coreTypes.Map)
) {
accept('error', `Expected type '${coreTypes.List}' or '${coreTypes.Map}' but got '${receiverType}'.`, {
node: node.receiver,
code: CODE_TYPE_MISMATCH,
Expand All @@ -112,7 +116,7 @@ export const indexedAccessIndexMustHaveCorrectType = (services: SafeDsServices)

return (node: SdsIndexedAccess, accept: ValidationAcceptor): void => {
const receiverType = typeComputer.computeType(node.receiver);
if (receiverType === coreTypes.List) {
if (typeChecker.isAssignableTo(receiverType, coreTypes.List)) {
const indexType = typeComputer.computeType(node.index);
if (!typeChecker.isAssignableTo(indexType, coreTypes.Int)) {
accept('error', `Expected type '${coreTypes.Int}' but got '${indexType}'.`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('SafeDsTypeChecker', async () => {
{
type1: callableType8,
type2: callableType7,
expected: false,
expected: true,
},
{
type1: callableType9,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fun f1(param: (a: Int, b: Int, c: Int) -> r: Int)
fun f2(param: (a: Int, b: Int, c: Int) -> ())

segment test(param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_3") param3: Int = 0) {
f1((param1: Int, param2: Int, param3: Int = 0) -> 1);
f2((param1: Int, param2: Int, param3: Int = 0) {});
f1((a: Int, b: Int, c: Int = 0) -> 1);
f2((a: Int, b: Int, c: Int = 0) {});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Segments ---------------------------------------------------------------------

def test(param1, param_2, param_3=0):
f1(lambda param1, param2, param3=0: 1)
def __gen_block_lambda_0(param1, param2, param3=0):
f1(lambda a, b, c=0: 1)
def __gen_block_lambda_0(a, b, c=0):
pass
f2(__gen_block_lambda_0)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipeline test {
f1((a: Int, b: Int = 2) {
yield d = g();
});
f1((a: Int, c: Int) {
f1((a: Int, b: Int) {
yield d = g();
});
f2(() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def __gen_block_lambda_0(a, b=2):
__gen_block_lambda_result_d = g()
return __gen_block_lambda_result_d
f1(__gen_block_lambda_0)
def __gen_block_lambda_1(a, c):
def __gen_block_lambda_1(a, b):
__gen_block_lambda_result_d = g()
return __gen_block_lambda_result_d
f1(__gen_block_lambda_1)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fun f(param: (a: Int, b: Int) -> r: Int)

pipeline test {
f((a, b = 2) -> 1);
f((a, c) -> 1);
f((a, b) -> 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

def test():
f(lambda a, b=2: 1)
f(lambda a, c: 1)
f(lambda a, b: 1)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class C() {
attr a: Int
@PythonName("c") attr b: Int

@PythonCall("$param.i($this)") fun i(param: Any?)
@PythonCall("$param.i($this)") fun i(param: Any?) -> result: Boolean
}

fun factory() -> instance: C?
Expand Down

0 comments on commit 67f3348

Please sign in to comment.