mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
compiler error instead of crash when using functioncall without returnvalue
This commit is contained in:
parent
1c1da8e38e
commit
a00c39e9cf
@ -157,7 +157,7 @@ private class BuiltinFunctionsFacade(functions: Map<String, FSignature>): IBuilt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(func.known_returntype==null)
|
else if(func.known_returntype==null)
|
||||||
throw IllegalArgumentException("builtin function $name can't be used here because it doesn't return a value")
|
return null // builtin function $name can't be used here because it doesn't return a value
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
if(!idt.isKnown) {
|
if(!idt.isKnown) {
|
||||||
errors.err("return type mismatch", assignment.value.position)
|
errors.err("return type mismatch", assignment.value.position)
|
||||||
}
|
}
|
||||||
if(stmt.returntypes.size <= 1 && stmt.returntypes.single() isNotAssignableTo idt.typeOrElse(DataType.BYTE)) {
|
if(stmt.returntypes.isEmpty() || (stmt.returntypes.size == 1 && stmt.returntypes.single() isNotAssignableTo idt.typeOrElse(DataType.BYTE))) {
|
||||||
errors.err("return type mismatch", assignment.value.position)
|
errors.err("return type mismatch", assignment.value.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -953,6 +953,24 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if a function that doesn't return a value, is used in an expression or assignment
|
||||||
|
if(targetStatement is Subroutine) {
|
||||||
|
if(targetStatement.returntypes.isEmpty()) {
|
||||||
|
if(functionCall.parent is Expression || functionCall.parent is Assignment)
|
||||||
|
errors.err("subroutine doesn't return a value", functionCall.position)
|
||||||
|
else
|
||||||
|
TODO("check $functionCall ${functionCall.parent}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(targetStatement is BuiltinFunctionStatementPlaceholder) {
|
||||||
|
if(builtinFunctionReturnType(targetStatement.name, functionCall.args, program).isUnknown) {
|
||||||
|
if(functionCall.parent is Expression || functionCall.parent is Assignment)
|
||||||
|
errors.err("function doesn't return a value", functionCall.position)
|
||||||
|
else
|
||||||
|
TODO("check builtinfunc $functionCall ${functionCall.parent}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.visit(functionCall)
|
super.visit(functionCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user