Skip to content

Commit

Permalink
Merge pull request #3071 from michaellilltokiwa/ast--remove-special-h…
Browse files Browse the repository at this point in the history
…andling-in-for-anonymous-in-findFieldDefInScope

ast: remove special handling in for anonymous in findFieldDefInScope
  • Loading branch information
fridis committed May 17, 2024
2 parents c45045e + 0fb219b commit 2b90909
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
32 changes: 15 additions & 17 deletions src/dev/flang/ast/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public Call(SourcePosition pos,
Expr target,
AbstractFeature anonymous)
{
this(pos, target, null, Expr.NO_EXPRS);
this(pos, target, anonymous.featureName().baseName(), Expr.NO_EXPRS);
this._calledFeature = anonymous;
}

Expand Down Expand Up @@ -874,24 +874,22 @@ void setToErrorState()
FeatureAndOuter partiallyApplicableAlternative(Resolution res, AbstractFeature outer, AbstractType expectedType)
{
if (PRECONDITIONS) require
(expectedType.isFunctionType());
(expectedType.isFunctionType(),
_name != null);

FeatureAndOuter result = null;
if (_name != null) // NYI: CLEANUP: _name is null for call to anonymous inner feature. Should better be the name of the called feature
{
var n = expectedType.arity() + (_wasImplicitImmediateCall ? _originalArgCount : _actuals.size());
var newName = newNameForPartial(expectedType);
var name = newName != null ? newName : _name;

// if loadCalledFeatureUnlessTargetVoid has found a suitable called
// feature in an outer feature, it will have replaced a null _target, so
// we check _originalTarget here to not check all outer features:
var traverseOuter = _originalTarget == null;
var targetFeature = traverseOuter ? outer : targetFeature(res, outer);
var fos = res._module.lookup(targetFeature, name, this, traverseOuter, false);
var calledName = FeatureName.get(name, n);
result = FeatureAndOuter.filter(fos, pos(), FeatureAndOuter.Operation.CALL, calledName, ff -> ff.valueArguments().size() == n);
}
var n = expectedType.arity() + (_wasImplicitImmediateCall ? _originalArgCount : _actuals.size());
var newName = newNameForPartial(expectedType);
var name = newName != null ? newName : _name;

// if loadCalledFeatureUnlessTargetVoid has found a suitable called
// feature in an outer feature, it will have replaced a null _target, so
// we check _originalTarget here to not check all outer features:
var traverseOuter = _originalTarget == null;
var targetFeature = traverseOuter ? outer : targetFeature(res, outer);
var fos = res._module.lookup(targetFeature, name, this, traverseOuter, false);
var calledName = FeatureName.get(name, n);
result = FeatureAndOuter.filter(fos, pos(), FeatureAndOuter.Operation.CALL, calledName, ff -> ff.valueArguments().size() == n);
return result;
}

Expand Down
12 changes: 1 addition & 11 deletions src/dev/flang/ast/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ public class Feature extends AbstractFeature
private Visi _visibility;
public Visi visibility()
{
return
// NYI anonymous feature should have correct visibility set.
isAnonymousInnerFeature()
? (state().atLeast(State.FINDING_DECLARATIONS) ? outer().visibility() : Visi.UNSPECIFIED)
: _visibility == Visi.UNSPECIFIED
return _visibility == Visi.UNSPECIFIED
? Visi.PRIV
: _visibility;
}
Expand Down Expand Up @@ -2089,12 +2085,6 @@ public Call action(Call c, AbstractFeature outer)
{ // Found the call, so we got the result!
found();
}
else if (c.calledFeatureKnown() &&
c.calledFeature() instanceof Feature cf && cf.isAnonymousInnerFeature() &&
c.calledFeature() == inner)
{ // NYI: Special handling for anonymous inner features that currently do not appear as expressions
found();
}
else if (c == Call.ERROR && curres[1] == null)
{
curres[1] = Types.f_ERROR;
Expand Down
8 changes: 1 addition & 7 deletions src/dev/flang/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3084,13 +3084,7 @@ Expr anonymous()
var f = Feature.anonymous(pos, r, i, c, b);
var ca = new Call(pos, f);
sameLine(sl);
return ca;
// NYI: This would simplify the code (in Feature.findFieldDefInScope that
// has special handling for c.calledFeature().isAnonymousInnerFeature()) but
// does not work yet, probably because of too much that is done explicitly
// for anonymous features.
//
// return new Block(b.closingBracePos_, new List<>(f, ca));
return new Block(new List<>(f, ca));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
tree(A type : property.orderable) : choice nil (Node A (tree A) (tree A)) is
--^^^^
A closure cannot be built for a choice type. Forbidden accesses occur at
--CURDIR--/issue698.fz:38:13:
ref : Node A (tree A) (tree A)
------------^^^^
--CURDIR--/issue698.fz:38:7:
ref : Node A (tree A) (tree A)
------^
Expand Down

0 comments on commit 2b90909

Please sign in to comment.