D-Programming-Language/dmd — pull request #2877 by 9rnsr (2013-11-25 05:59:12+00:00)
Title: Issue 9271 - Forwarding lambda predicate with type inference causes segfault 

https://d.puremagic.com/issues/show_bug.cgi?id=9271

Root cause is in the wrong mangling scheme for nested templates.

Currently, if `TemplateInstance::enclosing != NULL`, `enclosing` is preferentially used for the `parent` of mangled name.
However, if same name templates are instantiated with same nested arguments, their mangled name will conflict.

It can be checked by using dmd debug print at the end of `FuncDeclaration::semantic3`.

Current:

```
-FuncDeclaration::semantic3('any!(__lambda1, string[]).any', sc = 003D92A0, loc = imports\test9271a.d(3))
mangle() = _D8test92714mainFZv30__T3anyS14main9__lambda1TAAyaZ3anyMFNaNbNfAAyaZb**
-FuncDeclaration::semantic3('any!((e) => e == "asd", string[]).any', sc = 003D8100, loc = test9271.d(5))
mangle() = _D8test92714mainFZv30__T3anyS14main9__lambda1TAAyaZ3anyMFNaNbNfAAyaZb
```

After merging this PR, they will be fixed to:

```
-FuncDeclaration::semantic3('any!(__lambda1, string[]).any', sc = 01B192A0, loc = imports\test9271a.d(3))
mangle() = _D7imports9test9271a3any30__T3anyS14main9__lambda1TAAyaZ3anyMFNaNbNfAAyaZb
-FuncDeclaration::semantic3('any!((e) => e == "asd", string[]).any', sc = 01B18100, loc = test9271.d(5))
mangle() = _D8test92713any30__T3anyS14main9__lambda1TAAyaZ3anyMFNaNbNfAAyaZb
```