From e5d9e61fcde02e4b40f96b91df06abf796b2587d Mon Sep 17 00:00:00 2001 From: Michael Lill Date: Thu, 3 Aug 2023 14:52:17 +0200 Subject: [PATCH 1/2] improve backward type propagation for arrays - fixes #169 --- src/dev/flang/ast/InlineArray.java | 6 ++--- .../Makefile | 27 +++++++++++++++++++ .../issue169.fz | 16 +++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/reg_issue169_backward_type_propagation_array/Makefile create mode 100644 tests/reg_issue169_backward_type_propagation_array/issue169.fz diff --git a/src/dev/flang/ast/InlineArray.java b/src/dev/flang/ast/InlineArray.java index 7807a7b72..e589ac751 100644 --- a/src/dev/flang/ast/InlineArray.java +++ b/src/dev/flang/ast/InlineArray.java @@ -119,7 +119,7 @@ AbstractType typeIfKnown() _elements.iterator()); _type = Types.t_ERROR; } - if (_type == null) + else { _type = t == null ? null : @@ -162,7 +162,7 @@ public Expr propagateExpectedType(Resolution res, AbstractFeature outer, Abstrac { e.propagateExpectedType(res, outer, elementType); } - _type = t; + _type = Types.resolved.f_array.resultTypeIfPresent(res, new List<>(elementType)); } } return this; @@ -181,7 +181,7 @@ private AbstractType elementType(AbstractType t) if (PRECONDITIONS) require (t != null); - if (t.featureOfType() == Types.resolved.f_array && + if (Types.resolved.f_array.inheritsFrom(t.featureOfType()) && t.generics().size() == 1) { return t.generics().get(0); diff --git a/tests/reg_issue169_backward_type_propagation_array/Makefile b/tests/reg_issue169_backward_type_propagation_array/Makefile new file mode 100644 index 000000000..704c75f62 --- /dev/null +++ b/tests/reg_issue169_backward_type_propagation_array/Makefile @@ -0,0 +1,27 @@ +# 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 +# +# Author: Fridtjof Siebert (siebert@tokiwa.software) +# +# ----------------------------------------------------------------------- + +override NAME = issue169 +include ../positive.mk diff --git a/tests/reg_issue169_backward_type_propagation_array/issue169.fz b/tests/reg_issue169_backward_type_propagation_array/issue169.fz new file mode 100644 index 000000000..b878127a8 --- /dev/null +++ b/tests/reg_issue169_backward_type_propagation_array/issue169.fz @@ -0,0 +1,16 @@ +issue169 => + + a array i32 := [] + b Sequence i32 := [] + c Sequence u8 := [] + d Sequence f32 := [0,1,2] + e Sequence (Sequence i16) := [[0,1],[2]] + # NYI does not work yet + # f := [u8 4, 3, 3] + + say (type_of a) + say (type_of b) + say (type_of c) + say (type_of d) + say (type_of e) + # say (type_of f) From 3df243d267dc615157608dd3607d31e954f58541 Mon Sep 17 00:00:00 2001 From: Michael Lill Date: Fri, 4 Aug 2023 13:09:19 +0200 Subject: [PATCH 2/2] add NYI comment --- src/dev/flang/ast/InlineArray.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dev/flang/ast/InlineArray.java b/src/dev/flang/ast/InlineArray.java index e589ac751..c4ab54049 100644 --- a/src/dev/flang/ast/InlineArray.java +++ b/src/dev/flang/ast/InlineArray.java @@ -181,6 +181,7 @@ private AbstractType elementType(AbstractType t) if (PRECONDITIONS) require (t != null); + // NYI see issue: #1817 if (Types.resolved.f_array.inheritsFrom(t.featureOfType()) && t.generics().size() == 1) {