From f9ed92dc3ae3ad384d3fa0743f87fc050737ab27 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 26 Nov 2018 22:12:36 +0100 Subject: [PATCH] fix function parameter datatype checks --- compiler/examples/test.p8 | 10 ---------- compiler/src/prog8/ast/AST.kt | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index f8cd7cbbf..301779a23 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -24,11 +24,6 @@ sub start() { c64.CHROUT(memubytearray[1]) c64.CHROUT(ubytearray[X]) c64.CHROUT(memubytearray[X]) - c64.CHROUT(b1) ; @todo fix compiler crash incompatible data types - c64.CHROUT(mb1) ; @todo fix compiler crash incompatible data types - c64.CHROUT(bytearray[1]) ; @todo fix compiler crash incompatible data types - c64.CHROUT(membytearray[1]) ; @todo fix compiler crash incompatible data types - c64.CHROUT(wordarray[1]) ; @todo fix compiler crash incompatible data types testsub(X) testsub(ub1) @@ -37,11 +32,6 @@ sub start() { testsub(memubytearray[1]) testsub(ubytearray[X]) testsub(memubytearray[X]) - testsub(b1) ; @todo should give datatype error - testsub(mb1) ; @todo should give datatype error - testsub(bytearray[1]) ; @todo should give datatype error - testsub(membytearray[1]) ; @todo should give datatype error - testsub(wordarray[1]) ; @todo should give datatype error return } diff --git a/compiler/src/prog8/ast/AST.kt b/compiler/src/prog8/ast/AST.kt index b10abfc44..1608e36bd 100644 --- a/compiler/src/prog8/ast/AST.kt +++ b/compiler/src/prog8/ast/AST.kt @@ -31,22 +31,22 @@ enum class DataType { ARRAY_W, ARRAY_F; - fun assignableTo(type: DataType) = + fun assignableTo(targetType: DataType) = when(this) { - UBYTE -> type in NumericDatatypes - BYTE -> type in NumericDatatypes - UWORD -> type in NumericDatatypes - WORD -> type in NumericDatatypes - FLOAT -> type in NumericDatatypes - STR -> type == STR || type==STR_S || type == UWORD - STR_P -> type == STR_P || type==STR_PS || type == UWORD - STR_S -> type == STR || type==STR_S || type == UWORD - STR_PS -> type == STR_P || type==STR_PS || type == UWORD - ARRAY_UB -> type == UWORD - ARRAY_B -> type == UWORD - ARRAY_UW -> type == UWORD - ARRAY_W -> type == UWORD - ARRAY_F -> type == UWORD + UBYTE -> targetType == UBYTE || targetType == UWORD || targetType == FLOAT + BYTE -> targetType == BYTE || targetType == WORD || targetType == FLOAT + UWORD -> targetType == UWORD || targetType == FLOAT + WORD -> targetType == WORD || targetType == FLOAT + FLOAT -> targetType == FLOAT + STR -> targetType == STR || targetType==STR_S || targetType == UWORD + STR_P -> targetType == STR_P || targetType==STR_PS || targetType == UWORD + STR_S -> targetType == STR || targetType==STR_S || targetType == UWORD + STR_PS -> targetType == STR_P || targetType==STR_PS || targetType == UWORD + ARRAY_UB -> targetType == UWORD + ARRAY_B -> targetType == UWORD + ARRAY_UW -> targetType == UWORD + ARRAY_W -> targetType == UWORD + ARRAY_F -> targetType == UWORD } }