-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue 22054 - Referencing a fwd-declared field results in many error messages #12801
Conversation
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
|
Note that your branch is missing #12671. That PR is related because it fixes This patch suffices for current master and produces a somewhat better error message: diff --git a/src/dmd/dclass.d b/src/dmd/dclass.d
index 9c5f0da2f..f9b4aba37 100644
--- a/src/dmd/dclass.d
+++ b/src/dmd/dclass.d
@@ -498,7 +498,7 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
if (!members || !symtab) // opaque or addMember is not yet done
{
// .stringof is always defined (but may be hidden by some other symbol)
- if (ident != Id.stringof && !(flags & IgnoreErrors))
+ if (ident != Id.stringof && !(flags & IgnoreErrors) && semanticRun < PASS.semanticdone)
error("is forward referenced when looking for `%s`", ident.toChars());
//*(char*)0=0;
return null;
|
Also would be good to test the behavior for opaque |
@MoonlightSentinel Your patch is superior, so I implemented that, however, I added a supplemental error for aggregated types. |
src/dmd/typesem.d
Outdated
if (auto fd = search_function(sym, Id.opDispatch)) | ||
errorSupplemental(loc, "potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message"); | ||
else if (!sym.members) | ||
errorSupplemental(loc, "`%s` `%s` is forward declared and does not have a body.", sym.kind, mt.toPrettyChars(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D does not support forward declarations, this should probably refer to an opaque type.
Also, can this error message be triggered for an actual forward reference error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D does not support forward declarations, this should probably refer to an opaque type.
changed.
Also, can this error message be triggered for an actual forward reference error?
Sorry, I don't understand what you mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symtab
might be null
if this error occurs early into in the semantic of exception
. But i think it's currently impossible to write code that could trigger such scenarios. (e.g. base classes/interface for opaque classes are rejected by the parser).
class Opaque : Check!Opaque;
class Check(T)
{
// Try to access T's members
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, forward reference errors are issued before noMember
is called.
Is this good to go? |
I would say so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
@MoonlightSentinel done. |
No description provided.