Skip to content

Fix Issue 930 - Templates inside templates used as mixins#10192

Merged
dlang-bot merged 1 commit intodlang:stablefrom
RazvanN7:Issue_930
Jul 18, 2019
Merged

Fix Issue 930 - Templates inside templates used as mixins#10192
dlang-bot merged 1 commit intodlang:stablefrom
RazvanN7:Issue_930

Conversation

@RazvanN7
Copy link
Contributor

template ATemplate(T) {
   template ATemplate() {
       void foo() {
           T x = 2; // this line causes an error
           printf("Hi\n");
       }
   }
}

class TheClass(alias MixIt)
{
    mixin MixIt;
}


void main()
{
    auto val = new TheClass!(ATemplate!(int));
    val.foo();
}

When a template is instantiated, the template parameters are declared as aliases to the instantiation types in the scope of the template instance. In this situation, the mixin simply syntax copies the Atemplate() without any knowledge of its parent scope, therefore the alias for the T type is lost.

My patch checks for this particular case and the lost types are brought in the mixin scope.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 17, 2019

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
930 minor Templates inside templates used as mixins

Testing this PR locally

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

dub fetch digger
dub run digger -- build "stable + dmd#10192"

@thewilsonator
Copy link
Contributor

This is a pretty simple fix, might as well target stable.

@RazvanN7
Copy link
Contributor Author

Fair enough.

@RazvanN7 RazvanN7 changed the base branch from master to stable July 17, 2019 13:49
---
*/

import core.stdc.stdio;
Copy link

Choose a reason for hiding this comment

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

You can declare a dummy function with the same signature as printf.

Copy link
Contributor Author

@RazvanN7 RazvanN7 Jul 17, 2019

Choose a reason for hiding this comment

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

I could delete it altogether, I just wanted to preserve the initial bug report as is.

Copy link

Choose a reason for hiding this comment

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

and get ridof the import in case it was not clear

Copy link

Choose a reason for hiding this comment

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

I could delete it altogether, I just wanted to preserve the initial bug report as is

yes sorry crossed post. Remove the import and use local dummy please and it's good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted the printf; it's a compilable test anyway.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM

@dlang-bot dlang-bot merged commit 9f3c29a into dlang:stable Jul 18, 2019
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.

3 participants