Skip to content

Commit

Permalink
Merge pull request #1814 from michaellilltokiwa/issue/169
Browse files Browse the repository at this point in the history
improve backward type propagation for arrays
  • Loading branch information
fridis committed Aug 4, 2023
2 parents 86e2195 + 3df243d commit 52bf945
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/dev/flang/ast/InlineArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ AbstractType typeIfKnown()
_elements.iterator());
_type = Types.t_ERROR;
}
if (_type == null)
else
{
_type =
t == null ? null :
Expand Down Expand Up @@ -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;
Expand All @@ -181,7 +181,8 @@ private AbstractType elementType(AbstractType t)
if (PRECONDITIONS) require
(t != null);

if (t.featureOfType() == Types.resolved.f_array &&
// NYI see issue: #1817
if (Types.resolved.f_array.inheritsFrom(t.featureOfType()) &&
t.generics().size() == 1)
{
return t.generics().get(0);
Expand Down
27 changes: 27 additions & 0 deletions tests/reg_issue169_backward_type_propagation_array/Makefile
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# Author: Fridtjof Siebert ([email protected])
#
# -----------------------------------------------------------------------

override NAME = issue169
include ../positive.mk
16 changes: 16 additions & 0 deletions tests/reg_issue169_backward_type_propagation_array/issue169.fz
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 52bf945

Please sign in to comment.