[trivial] Improve error message when aggregate template is used as a type#7769
[trivial] Improve error message when aggregate template is used as a type#7769dlang-bot merged 2 commits intodlang:masterfrom
Conversation
|
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:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
0d37000 to
5548284
Compare
|
CircleCi failure is unrelated - #7770 |
src/dmd/typesem.d
Outdated
| 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", |
There was a problem hiding this comment.
I suggest an improvement:
template %s `%s` is used as a type without instantiation; to instantiate it use `%s!(arguments)`
There was a problem hiding this comment.
What if the user has a variable called arguments already in scope? They might get confused.
There was a problem hiding this comment.
@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.
WalterBright
left a comment
There was a problem hiding this comment.
Please make the change I suggested. A good error message should say what is wrong, and suggest corrective action.
Make it clear with aggregate templates that they are templates and haven't been instantiated.
Note:
s.kindis e.g. just "struct" for aggregate templates. Non-aggregates say "template".Note: When
td.onememberis 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