Skip to content

[trivial] Improve error message when aggregate template is used as a type#7769

Merged
dlang-bot merged 2 commits intodlang:masterfrom
ntrel:no-type
Jan 26, 2018
Merged

[trivial] Improve error message when aggregate template is used as a type#7769
dlang-bot merged 2 commits intodlang:masterfrom
ntrel:no-type

Conversation

@ntrel
Copy link
Contributor

@ntrel ntrel commented Jan 24, 2018

Make it clear with aggregate templates that they are templates and haven't been instantiated.

Note: s.kind is e.g. just "struct" for aggregate templates. Non-aggregates say "template".
Note: When td.onemember is an alias, we don't know if it resolves to a type or not until the template is instantiated.

http://forum.dlang.org/post/p49c55$m65$1@digitalmars.com

@dlang-bot dlang-bot added the Review:Trivial typos, formatting, comments label Jan 24, 2018
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@ntrel ntrel force-pushed the no-type branch 2 times, most recently from 0d37000 to 5548284 Compare January 24, 2018 17:04
Copy link
Member

@quickfur quickfur left a comment

Choose a reason for hiding this comment

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

LGTM.

@wilzbach
Copy link
Contributor

CircleCi failure is unrelated - #7770

s.error(loc, "is used as a type");
auto td = s.isTemplateDeclaration;
if (td && td.onemember && td.onemember.isAggregateDeclaration)
mtype.error(loc, "%s template `%s` is used as a type without instantiation",
Copy link
Member

Choose a reason for hiding this comment

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

I suggest an improvement:

template %s `%s` is used as a type without instantiation; to instantiate it use `%s!(arguments)`

Copy link
Member

Choose a reason for hiding this comment

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

What if the user has a variable called arguments already in scope? They might get confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MetaLang Maybe use %s!() instead? That way if the template requires arguments they will get an error to that effect, and this error may come up when the template doesn't need arguments anyway, as in the forum example.

Note: s.kind is just "struct" for struct templates.
Note: When td.onemember is an alias, we don't know if it resolves to a
type or not until the template is instantiated.
@wilzbach
Copy link
Contributor

CircleCi failure is unrelated - #7770

In lack of someone wanting merging #7770, I rebased the PR. This will fix the CircleCi failure too.

Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

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

Please make the change I suggested. A good error message should say what is wrong, and suggest corrective action.

@dlang-bot dlang-bot merged commit a05586b into dlang:master Jan 26, 2018
@ntrel ntrel deleted the no-type branch January 30, 2018 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants