Skip to content

Commit

Permalink
air: fix field falsly detected to be redefined
Browse files Browse the repository at this point in the history
fixes #3369
  • Loading branch information
michaellilltokiwa committed Jul 19, 2024
1 parent b5644aa commit 63611f3
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/dev/flang/air/Clazz.java
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,12 @@ private AbstractFeature findRedefinition(AbstractFeature f)
// first look in the feature itself
AbstractFeature result = _flu.lookupFeature(feature(), fn, f);

if (!result.redefinesFull().contains(f) && result != f)
{
// feature with same name, but not a redefinition
result = null;
}

// the inherited feature might not be
// visible to the inheriting feature
var chain = tf.findInheritanceChain(f.outer());
Expand All @@ -1017,6 +1023,11 @@ private AbstractFeature findRedefinition(AbstractFeature f)
for (var p: chain)
{
result = _flu.lookupFeature(p.calledFeature(), fn, f);
if (!result.redefinesFull().contains(f) && result != f)
{
// feature with same name, but not a redefinition
result = null;
}
if (result != null)
{
break;
Expand Down
15 changes: 15 additions & 0 deletions src/dev/flang/ast/AbstractFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import dev.flang.util.Errors;
import dev.flang.util.FuzionConstants;
Expand Down Expand Up @@ -1881,6 +1883,19 @@ public boolean isNonArgumentField()
}


/**
* In constrast to redefines() this does not just contain direct redefines()
* but also redefinitions of redefinitions of arbitrary depth.
*/
public Set<AbstractFeature> redefinesFull()
{
return redefines()
.stream()
.flatMap(x -> Stream.concat(Stream.of(x), x.redefinesFull().stream()))
.collect(Collectors.toSet());
}


/**
* this feature as a human readable string
*/
Expand Down
26 changes: 26 additions & 0 deletions tests/reg_issue3369/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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
#
# -----------------------------------------------------------------------

override NAME = reg_issue3369
export FUZION_OPTIONS=-sourceDirs=.
include ../simple.mk
6 changes: 6 additions & 0 deletions tests/reg_issue3369/child.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public child : parent is

redef get_name => "CHILD"

# NYI: This caused a java exception
name := get_name
7 changes: 7 additions & 0 deletions tests/reg_issue3369/parent.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public parent is

module get_name => "PARENT"

name := get_name

public introduce => "I'm $name"
26 changes: 26 additions & 0 deletions tests/reg_issue3369/reg_issue3369.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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 reg_issue3369
#
# -----------------------------------------------------------------------

reg_issue3369 =>

say child.introduce
Empty file.
1 change: 1 addition & 0 deletions tests/reg_issue3369/reg_issue3369.fz.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm CHILD
3 changes: 1 addition & 2 deletions tests/visibility_modules/main.fz
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ m =>

say b.get_any.as_string // indirectly calling private feature

# NYI this does not work yet
# say b.get_field
say b.get_field
1 change: 1 addition & 0 deletions tests/visibility_modules/main.fz.expected_out
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ hello_a from b
calling b.get_aa.aaa
aaa
priv
0

0 comments on commit 63611f3

Please sign in to comment.