[Issue 3276] Recursion broken by alias template parameter

2015-06-08 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3276

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

Version|2.032   |D2

--


[Issue 3276] Recursion broken by alias template parameter

2010-12-05 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3276


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||bugzi...@digitalmars.com
 Resolution||FIXED


--- Comment #4 from Walter Bright bugzi...@digitalmars.com 2010-12-05 
23:00:13 PST ---
http://www.dsource.org/projects/dmd/changeset/784

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


Re: [Issue 3276] Recursion broken by alias template parameter

2010-11-03 Thread Don

d-bugm...@puremagic.com wrote:

http://d.puremagic.com/issues/show_bug.cgi?id=3276
--- Comment #3 from Shin Fujishiro rsi...@gmail.com 2010-11-02 22:11:39 PDT 
---



The patch passed dmd, druntime and phobos tests.  It couldn't pass the broken
test (runnable/interpret.d) though.


What do you mean, the broken test? It needs to pass, unless you have 
modified the file from the one in svn. (It fails on Linux with -O, but 
that is not part of the test).




[Issue 3276] Recursion broken by alias template parameter

2010-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3276


Shin Fujishiro rsi...@gmail.com changed:

   What|Removed |Added

 CC||rsi...@gmail.com


--- Comment #2 from Shin Fujishiro rsi...@gmail.com 2010-11-02 22:09:58 PDT 
---
The bug happens if a recursive template is instantiated via an alias:

  alias Bug3276 W;
  alias W!true w;

In template.c, the following if at the line 4304 tries to get the relevant
TemplateDeclaration for doing recursion:

TemplateDeclaration *TemplateInstance::findTemplateDeclaration(Scope *sc)
{
...
TemplateInstance *ti;
if (s-parent 
(ti = s-parent-isTemplateInstance()) != NULL)
{
if (
(ti-name == id ||
 ti-toAlias()-ident == id)// -- the cause

ti-tempdecl)
...
}

Here 'this' refers to the recursive instantiation Bug3276!(false) and
id=Bug3276 is its identifier.  'ti' is the enclosing TemplateInstance (i.e.
W!(true)).

The test sees if the identifier 'id' used in the instantiation
Bug3276!(false) is the same as the one of enclosing 'ti'.  But 'ti' was
instantiated with the aliased identifier (ti-name=W), so the first condition
isn't met.

Then it tests the next condition: ti-toAlias()-ident.  It dives into the
following code in TemplateInstance::toAlias():

if (aliasdecl)
{
return aliasdecl-toAlias();
}

Here 'aliasdecl' is the result of the eponymous template Bug3276!(true),
and it's exactly the alias Bug3276!(false) analyzing now. 
AliasDeclaration::toAlias() does the follownig check:

if (inSemantic)
{   error(recursive alias declaration);
aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
}

Since it's in semantic, the compiler raises the error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3276] Recursion broken by alias template parameter

2010-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3276


Shin Fujishiro rsi...@gmail.com changed:

   What|Removed |Added

   Keywords||patch


--- Comment #3 from Shin Fujishiro rsi...@gmail.com 2010-11-02 22:11:39 PDT 
---
Patch against dmd r737.

--- src/template.c
+++ src/template.c
@@ -4304,11 +4304,7 @@ TemplateDeclaration
*TemplateInstance::findTemplateDeclaration(Scope *sc)
 if (s-parent 
 (ti = s-parent-isTemplateInstance()) != NULL)
 {
-if (
-(ti-name == id ||
- ti-toAlias()-ident == id)
-
-ti-tempdecl)
+if (ti-tempdecl  ti-tempdecl-ident == id)
 {
 /* This is so that one can refer to the enclosing
  * template, even if it has the same name as a member


Getting 'ti' for recognizing recursion is good; but the identifier should be
compared with the one of a TemplateDeclaration, not the TemplateInstance.  As
happened in the reported bug, ti-name is not always the appropriate identifier
for recursion check.

The patch removes ti-toAlias() for good.  TemplateInstance::toAlias() does
*not* resolve alias of itself; as seen in its implementation, it actually
returns the result of the template and makes no sense.  'id' has to be
compared with ti-tempdecl-ident.

The patch passed dmd, druntime and phobos tests.  It couldn't pass the broken
test (runnable/interpret.d) though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3276] Recursion broken by alias template parameter

2010-05-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3276


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Keywords||rejects-valid
 CC||clugd...@yahoo.com.au
Summary|Mutual recursion broken in  |Recursion broken by alias
   |type templates  |template parameter


--- Comment #1 from Don clugd...@yahoo.com.au 2010-05-12 12:35:28 PDT ---
Reduced test case shows it doesn't involve mutual recursion (original title was
Mutual recursion broken in type templates)

template Bug3276(bool B) {
   static if (B)
  alias Bug3276!(false) Bug3276;
   else
   alias double Bug3276;
}

template Bug3276_b(alias W) {
alias W!(true) Bug3276_b;
}

alias Bug3276_b!(Bug3276) Bug3276_c;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---