Skip to content

Comments

[REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type#5202

Merged
MartinNowak merged 1 commit intodlang:masterfrom
9rnsr:fix14965
Mar 7, 2016
Merged

[REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type#5202
MartinNowak merged 1 commit intodlang:masterfrom
9rnsr:fix14965

Conversation

@9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Oct 19, 2015

https://issues.dlang.org/show_bug.cgi?id=14965

If a function symbol is used, its overload resolution should be deferred until:

func(...)           // CallExp.semantic
func.mangleof       // DotIdExp.semanticY
typeof(func)        // TypeTypeof.resolve
typeof(&func)       // TypeTypeof.resolve
auto v = &func;     // ExpInitializer.inferType
&func;              // ExpStatement.semantic
return &func;       // ReturnStatement

When the semantic analysis reaches to them, the function forward reference can beome actual error.

Other use of 'func' should be treated as a property-like function call (done in resolveProperties) and finally handled in CallExp.


Each preparation cleanup/refactoring changes are separated into following pull requests.

@9rnsr 9rnsr force-pushed the fix14965 branch 2 times, most recently from d85b607 to 2c56587 Compare October 23, 2015 03:51
@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
14965 [REG2.031] Forward reference to inferred return type of function call when using auto return type

@9rnsr 9rnsr force-pushed the fix14965 branch 4 times, most recently from 941b4f2 to b42243d Compare December 3, 2015 14:30
@9rnsr 9rnsr force-pushed the fix14965 branch 3 times, most recently from 66b06ff to e8fc4e0 Compare February 5, 2016 14:38
@9rnsr 9rnsr force-pushed the fix14965 branch 3 times, most recently from faa0421 to cfc9a5c Compare February 14, 2016 12:26
@9rnsr 9rnsr mentioned this pull request Feb 14, 2016
@9rnsr 9rnsr force-pushed the fix14965 branch 2 times, most recently from 4d2f9e0 to 2be998c Compare February 16, 2016 00:52
@9rnsr
Copy link
Contributor Author

9rnsr commented Feb 16, 2016

Now this PR contains only one bugfix commit. Ready to go.

…on call when using auto return type

If a function symbol is used, its overload resolution should be deferred until:

```d
func(...)           // CallExp.semantic
func.mangleof       // DotIdExp.semanticY
typeof(func)        // TypeTypeof.resolve
typeof(&func)       // TypeTypeof.resolve
auto v = &func;     // ExpInitializer.inferType
&func;              // ExpStatement.semantic
return &func;       // ReturnStatement
```

When the semantic analysis reaches to them, the function forward reference can beome actual error.

Other use of 'func' should be treated as a property-like function call (done in `resolveProperties`) and finally handled in `CallExp`.
@MartinNowak
Copy link
Member

It's very maintenance intensive to do something by dealing with all occurrences of it in the language.
While your work is an improvement, can we boil it further down to something more fundamental like requiring the type of an expression.

@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 2, 2016

I'm continuously boiling down things. It's easy to add one new thing quickly, but it's dangerous because we should handle all interactions at once between the new thing and other all existing AST entities. So, we usually should be conservative not to add new things.

(OT: I'm proposing to add a new AST entity "ambiguous function type and its derived types" in #2130, but the PR didn't get enough response during 3 years.)

@MartinNowak
Copy link
Member

It's easy to add one new thing quickly, but it's dangerous because we should handle all interactions at once between the new thing and other all existing AST entities. So, we usually should be conservative not to add new things.

I think we should try to refactor our code, so it's less hard to add all those interactions. It's also a big maintenance overhead to deal w/ behavior that's scattered throughout the codebase.
But we should still be conservative to add new features, simply b/c we want the language to stabilize.

@MartinNowak
Copy link
Member

So to rephrase my question, can we combine this check w/ something else we already do?
Or at least put it into a more abstract needsExactType/needsResolvedSymbol function or so?
What's the common denominator of all the above mentioned expressions. Why is AddrExpr in ReturnStatement different from AddrExp in initializer?
We already have inferType for when the result of an expression depends on the LHS.

@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 7, 2016

I think we should try to refactor our code

I agree with you at all, but refactoring is less priority than regression fixes. So I usually don't do unuseful refactoring for bugfixes near the future.

can we combine this check w/ something else we already do?

No we cant yet, because function overload handling is yet incomplete (See issue 1983 and others). In other words, we are in progress to find it.

Or at least put it into a more abstract

It was impossible. In this PR, I added two abstracts isFuncAddress and checkForwardRef. In early stage I tried to merge them into one, but couldn't because of subtle existing behavior differences in TypeTypeof, AddrExp, etc.
Now, the differences stand out by the two abstracts. Of course later we can decide how to handle them, but we should not touch them now, because this is for 14965 bugfix.

@MartinNowak
Copy link
Member

Auto-merge toggled on

MartinNowak added a commit that referenced this pull request Mar 7, 2016
[REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type
@MartinNowak MartinNowak merged commit 624ad66 into dlang:master Mar 7, 2016
@9rnsr 9rnsr deleted the fix14965 branch March 8, 2016 00:50
@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 8, 2016

@MartinNowak Thanks!

tramker added a commit to tramker/dmd that referenced this pull request Mar 11, 2016
[REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants