Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/lock_free/src/lock_free/Sieve_Cache.fz
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Sieve_Cache(K type : property.hashable, V type, public capacity i32) ref

public redef as_string String =>
for res := "", res + "{n.val} (Visited: {n.val.visited.read})" + (if n.val.next.read?? then " -> " else "")
n := head.read, n.val.next
n := head.read, n.val.next.read
while n??
else
res
2 changes: 1 addition & 1 deletion src/dev/flang/ast/AbstractFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ public AbstractType handDownNonOpen(Resolution res, AbstractType t, AbstractFeat
if (PRECONDITIONS) require
(!t.isOpenGeneric(),
heir != null,
res == null || res.state(heir).atLeast(State.CHECKING_TYPES));
res == null || res.state(heir).atLeast(State.RESOLVED_SUGAR2));

var a = handDown(res, new AbstractType[] { t }, heir);

Expand Down
5 changes: 5 additions & 0 deletions src/dev/flang/ast/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,11 @@ void checkTypes(Resolution res, Context context)
if (CHECKS) check
(res._options.isLanguageServer() || Errors.any() || _type != null);

if (_calledFeature instanceof Feature cf && !cf.state().atLeast(State.CHECKING_TYPES))
{ // make sure argument types, if inferred from actual calls, are all known
cf.checkTypes(res);
}

if (_calledFeature != null &&
context.outerFeature() != Types.resolved.f_effect_static_finally &&
(_calledFeature == Types.resolved.f_effect_finally ||
Expand Down
31 changes: 29 additions & 2 deletions src/dev/flang/ast/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ void typeInference(Resolution res)
* @param res this is called during type resolution, res gives the resolution
* instance.
*/
void checkTypes(Resolution res)
private void checkTypes0(Resolution res)
{
if (PRECONDITIONS) require
(_state == State.RESOLVED_SUGAR2);
Expand Down Expand Up @@ -2022,6 +2022,30 @@ void checkTypes(Resolution res)
}


/**
* Perform static type checking, i.e., make sure, that for all assignments from
* actual to formal arguments or from values to fields, the types match.
*
* checkTypes also has the side-effect of collecting feature reault types, so
* this might be called repeatedly, in particular for kind FieldActual where
* this depends on all the call sites, even those that might have been added
* during RESOLVING_SUGAR2.
*
* @param res this is called during type resolution, res gives the resolution
* instance.
*/
void checkTypes(Resolution res)
{
if (PRECONDITIONS) require
(_state.atLeast(State.RESOLVED_SUGAR2));

if (!_state.atLeast(State.CHECKING_TYPES)) // make sure we check types only once
{
checkTypes0(res);
}
}


/**
* Check native features result and argument
* types for legality.
Expand Down Expand Up @@ -2375,7 +2399,10 @@ else if (isOuterRef())
result = result.resolve(res, outer().context());
}

if (result != null)
if (result != null &&
// do not remember the result for an argument field whose type is
// derived from the actual argument since we might still encounter more calls.
(_impl._kind != Impl.Kind.FieldActual || state().atLeast(State.CHECKING_TYPES)))
{
// FORWARD_CYCLIC should be returned only once.
// We then want to return t_ERROR.
Expand Down
4 changes: 4 additions & 0 deletions src/dev/flang/ast/Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ else if (result == Types.t_ERROR)
AstErrors.incompatibleTypesOfActualArguments(formalArg, types, positions);
}
}
else if (result == Types.t_ERROR)
{
result = null; // not urgent, we will report an error during CHECKING_TYPES phase.
}
if (POSTCONDITIONS) ensure
(!urgent || result != null);

Expand Down
25 changes: 25 additions & 0 deletions tests/reg_issue5560/Makefile
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion test Makefile
#
# -----------------------------------------------------------------------

override NAME = reg_issue5560
include ../simple.mk
51 changes: 51 additions & 0 deletions tests/reg_issue5560/reg_issue5560.fz
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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_issue5560
#
# -----------------------------------------------------------------------

# Failure to infer arguments types from call site results in too many errors
#
reg_issue5560 =>

# Original example from #5560: This should produce onle one error
#
# This is supposed to infer the type of argument v from the calls to f.
#
#
# This should fail since the argument types in both calls are different
# (String vs i32), but before #5560 was fixed, it first reports an error
# in call `f 1` that is actually correct for itself, only the second
# error clarifies why there is a problem:
#
f(v) => say v
f "a"
f 1

# a second example with more call sites. This should currently produce one error.
#
# NYI: UNDER DEVELOPMENT: once #5561 is fixed, this might actually work and not
# produce any error
#
g(v) => say v
g "aa"
g nil
g (option "")
g Any
31 changes: 31 additions & 0 deletions tests/reg_issue5560/reg_issue5560.fz.expected_err
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

--CURDIR--/reg_issue5560.fz:38:5: error 1: Type inference from actual arguments failed due to incompatible types of actual arguments
f(v) => say v
----^
For the formal argument 'reg_issue5560.f.v' the following incompatible actual arguments where found for type inference:
actual is value of type 'codepoint' at --CURDIR--/reg_issue5560.fz:39:5:
f "a"
----^^^
actual is value of type 'i32' at --CURDIR--/reg_issue5560.fz:40:5:
f 1
----^


--CURDIR--/reg_issue5560.fz:47:5: error 2: Type inference from actual arguments failed due to incompatible types of actual arguments
g(v) => say v
----^
For the formal argument 'reg_issue5560.g.v' the following incompatible actual arguments where found for type inference:
actual is value of type 'String' at --CURDIR--/reg_issue5560.fz:48:5:
g "aa"
----^^^^
actual is value of type 'nil' at --CURDIR--/reg_issue5560.fz:49:5:
g nil
----^^^
actual is value of type 'option String' at --CURDIR--/reg_issue5560.fz:50:6:
g (option "")
-----^^^^^^
actual is value of type 'Any' at --CURDIR--/reg_issue5560.fz:51:5:
g Any
----^^^

2 errors.
Empty file.
Loading