[Issue 13478] [REG2.066] Templates not emitted when also referenced in speculative contexts

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Sep 15 13:01:03 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13478

--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to David Nadlinger from comment #3)
> Explanation of what happens: During the inline scan semantic, the foo!int
> TemplateInstance in 'c' overwrites the instantiatingModule of the one in
> 'a', even though it is speculative.

-inline will invoke additional semantic3() phase, and it will modify
"instantiation graph" expressed by TemplateInstance::tinst and
instantiatingModule.

It's the issue that I tried to fix in
https://github.com/D-Programming-Language/dmd/pull/3948.


> Patch, but seems to not occur any longer
> on master for a different reason:
> 
> diff --git a/src/template.c b/src/template.c
> index c230f62..45010ec 100644
> --- a/src/template.c
> +++ b/src/template.c
> @@ -6259,7 +6259,7 @@ void TemplateInstance::semantic(Scope *sc, Expressions
> *fargs)
>  #if LOG
>              printf("\tit's a match with instance %p, %d\n", inst,
> inst->semanticRun);
>  #endif
> -            if (!inst->instantiatingModule ||
> inst->instantiatingModule->isRoot())
> +            if (!speculative && (!inst->instantiatingModule ||
> inst->instantiatingModule->isRoot()))
>                  inst->instantiatingModule = mi;
>              errors = inst->errors;
>              return;

Patch looks good. Even if a new instantiation (== 'this') is in non-root
module, when it's a speculatively instantiation (this->speculative == true), it
should not modify the instantiation graph (== inst->instantiatingModule).

Could you please open a Pull Request for 2.066 branch?

--


More information about the Digitalmars-d-bugs mailing list