diff --git a/src/dev/flang/ast/AbstractType.java b/src/dev/flang/ast/AbstractType.java index 47c41b7b43..1255eb01da 100644 --- a/src/dev/flang/ast/AbstractType.java +++ b/src/dev/flang/ast/AbstractType.java @@ -469,6 +469,7 @@ public boolean constraintAssignableFrom(AbstractType actual) var result = containsError() || actual.containsError() || this .compareTo(actual ) == 0 || + this .compareTo(Types.resolved.t_Any ) == 0 || actual.isVoid(); if (!result && !isGenericArgument()) { @@ -482,14 +483,12 @@ public boolean constraintAssignableFrom(AbstractType actual) (actual.feature() != null || Errors.any()); if (actual.feature() != null) { - if (actual.feature() == feature()) + if (actual.feature() == feature() && + genericsAssignable(actual)) // NYI: Check: What about open generics? { - if (genericsAssignable(actual)) // NYI: Check: What about open generics? - { - result = true; - } + result = true; } - if (!result) + else if (!actual.isChoice()) { for (var p: actual.feature().inherits()) { diff --git a/tests/reg_issue3362/Makefile b/tests/reg_issue3362/Makefile new file mode 100644 index 0000000000..68af1cfbd5 --- /dev/null +++ b/tests/reg_issue3362/Makefile @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test Makefile +# +# ----------------------------------------------------------------------- + +override NAME = reg_issue3362 +include ../simple_and_negative.mk diff --git a/tests/reg_issue3362/reg_issue3362.fz b/tests/reg_issue3362/reg_issue3362.fz new file mode 100644 index 0000000000..705ae38fc0 --- /dev/null +++ b/tests/reg_issue3362/reg_issue3362.fz @@ -0,0 +1,65 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test +# +# ----------------------------------------------------------------------- + +# Test choice type used as actual type parameter without matching the contstraing +# +reg_issue3362 is + + + # original example form issue #3362 + # + base32_test is + my_c : choice String (array u8) is + mk_choice(x my_c) => x + + # RFC 4618 test vectors + base32_test_vectors array (tuple my_c String) := + [(mk_choice "fo", "MZXQ===="), + (mk_choice "foo", "MZXW6===")] + + dummy_decode(arr array u8) outcome (array u8) => [0,0,0] + + dec_test => + for tup in base32_test_vectors do + (plain_expected, code) := tup + out := + match dummy_decode code.utf8.as_array + arr array u8 => + plain_actual := String.type.from_bytes arr + if plain_actual != plain_expected # 1. should flag an error: `choice String (array u8)` is not assignable to property.equatable + error "decoding $code produced '$plain_actual' but should have been '$plain_expected'" + else + outcome "ok" + e error => error "error in test data" + until !out.ok + out.err.as_string + else + "RFC 4648 test vectors are decoded correctly" + say dec_test + + + # minimalistic-example + # + c : choice i32 unit is + a c := 0 + _ := 0 = a # 2. should flag an error: `choice i32 unit` is not assignable to property.equatable diff --git a/tests/reg_issue3362/reg_issue3362.fz.expected_err b/tests/reg_issue3362/reg_issue3362.fz.expected_err new file mode 100644 index 0000000000..928461a6f3 --- /dev/null +++ b/tests/reg_issue3362/reg_issue3362.fz.expected_err @@ -0,0 +1,15 @@ + +--CURDIR--/reg_issue3362.fz:65:10: error 1: Incompatible type parameter + _ := 0 = a # 2. should flag an error: `choice i32 unit` is not assignable to property.equatable +---------^ +formal type parameter 'T' with constraint 'property.equatable' +actual type parameter 'reg_issue3362.this.c' + + +--CURDIR--/reg_issue3362.fz:49:29: error 2: Incompatible type parameter + if plain_actual != plain_expected # 1. should flag an error: `choice String (array u8)` is not assignable to property.equatable +----------------------------^^ +formal type parameter 'T' with constraint 'property.equatable' +actual type parameter 'reg_issue3362.this.my_c' + +2 errors. diff --git a/tests/reg_issue3362/reg_issue3362.fz.expected_out b/tests/reg_issue3362/reg_issue3362.fz.expected_out new file mode 100644 index 0000000000..e69de29bb2