Skip to content

Commit bc7b1cc

Browse files
committed
fix tuple type check issue
1 parent f93519d commit bc7b1cc

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/EliminateTuples.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,8 @@ private static ImStatementExpr inReturn(ImReturn parent, ImTupleExpr tupleExpr,
567567

568568
// Sanity:
569569
if (flatExprs.size() != returnVars.size()) {
570-
throw new RuntimeException("Tuple arity mismatch in return: RHS has "
571-
+ flatExprs.size() + " leaves, but function expects "
572-
+ returnVars.size());
570+
throw new CompileError(parent.getTrace(),
571+
"Cannot return tuple with " + flatExprs.size() + " element(s) from function expecting " + returnVars.size() + " element(s)");
573572
}
574573

575574
// 2) Assign per component, converting nulls to proper defaults of LHS type

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/TupleTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ public void nullStringInTuple() {
539539
" testSuccess()"
540540
);
541541
}
542+
@Test
543+
public void returnWrongTupleType() {
544+
testAssertErrorsLines(false, "Cannot return t2",
545+
"package test",
546+
"native testSuccess()",
547+
"tuple t1(int i, int i2)",
548+
"tuple t2(int i, int i2, int i3)",
549+
"let t2i = t2(1, 2, 3)",
550+
"function foo() returns t1",
551+
" return t2i",
552+
"init",
553+
" let x = foo()"
554+
);
555+
}
556+
542557
@Test
543558
public void nestedTupleArray() {
544559
testAssertOkLines(true,

0 commit comments

Comments
 (0)