Skip to content
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

Merged
merged 1 commit into from
Jul 8, 2021

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Jul 2, 2021

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 2, 2021

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
22054 regression Referencing a fwd-declared field results in many error messages

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

To target stable perform these two steps:

  1. Rebase your branch to upstream/stable:
git rebase --onto upstream/stable upstream/master
  1. Change the base branch of your PR to stable

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12801"

@RazvanN7 RazvanN7 changed the title Fix Issue 22054 - Referencing a fwd-declared field results in many er Fix Issue 22054 - Referencing a fwd-declared field results in many error messages Jul 2, 2021
@RazvanN7 RazvanN7 added Regression PRs that fix regressions Easy Review labels Jul 2, 2021
@MoonlightSentinel MoonlightSentinel self-requested a review July 2, 2021 13:13
@MoonlightSentinel
Copy link
Contributor

Note that your branch is missing #12671. That PR is related because it fixes ClassDeclaration.search (and others) to adhere to IgnoreErrors used during symbol resolution.

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;
Error: no property `what` for type `test22054.exception`

@MoonlightSentinel
Copy link
Contributor

Also would be good to test the behavior for opaque structs and enums (the latter won't work with your current patch - unless it's already handled another way)

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jul 5, 2021

@MoonlightSentinel Your patch is superior, so I implemented that, however, I added a supplemental error for aggregated types.

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Jul 5, 2021

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
}

Copy link
Contributor Author

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.

@thewilsonator
Copy link
Contributor

Is this good to go?

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jul 5, 2021

I would say so.

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

src/dmd/typesem.d Outdated Show resolved Hide resolved
@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jul 6, 2021

@MoonlightSentinel done.

@dlang-bot dlang-bot merged commit db89ef8 into dlang:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Bug Fix Regression PRs that fix regressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants