dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix Issue 13732 - non-member templates can use "template this"

Open ntrel opened this issue 1 year ago • 5 comments

Error if a TemplateThisParameter is declared when there's no parent aggregate type ~~or template (it could be for a mixin)~~.

ntrel avatar Sep 14 '22 13:09 ntrel

Thanks for your pull request and interest in making D better, @ntrel! 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
13732 normal Regular templates can use "template this", and they allow any type to be passed

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#14434"

dlang-bot avatar Sep 14 '22 13:09 dlang-bot

The grammar considers this a primary expression, so it should be a semantic error instead of parser error

dkorpel avatar Sep 14 '22 13:09 dkorpel

The grammar says this is just a token:

TemplateThisParameter: this TemplateTypeParameter

I'm not sure how to make it a semantic check. In templateparametersem.d there is Scope sc available, is that enough to determine if there's a parent type or template?

ntrel avatar Sep 14 '22 15:09 ntrel

The grammar says this is just a token:

You're right. What I really meant to say was: the grammar allows it outside an aggregate, so the parser should not reject it or the grammar needs to be updated as well.

I'm not sure how to make it a semantic check. In templateparametersem.d there is Scope sc available, is that enough to determine if there's a parent type or template?

I'll take a look later.

dkorpel avatar Sep 15 '22 19:09 dkorpel

In templateparametersem.d there is Scope sc available, is that enough to determine if there's a parent type or template?

I don't know what templateparametersem.d refers to, but I think you can do the check in dsymbolsem.d in either DsymbolSemanticVisitor.visit(TemplateDeclaration) or templateInstanceSemantic().

dkorpel avatar Sep 17 '22 19:09 dkorpel

@ntrel Just group the error messages in the test case and we can get this in.

RazvanN7 avatar Oct 03 '22 03:10 RazvanN7