D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7744 - Forward reference in string mixin
Summary: Forward reference in string mixin
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-03-20 20:16 UTC by Jordan Miner
Modified: 2013-11-23 21:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jordan Miner 2012-03-20 20:16:58 UTC
Hi, I was working on a grammar with Pegged and dmd crashed. I reduced it to:

class ZeroOrMore(Expr)
{
    enum name = "ZeroOrMore!("~Expr.name~")";
}
class Range(char begin, char end)
{
    enum name = "Range!("~begin~","~end~")";
}
mixin(q{
	class RubySource : ZeroOrMore!(DecLiteral)
	{
	}
	class DecLiteral : Range!('0','9')
	{
	}
});
void main() {
}

I get this error, followed by dmd crashing:

dmd_crash.d(13): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'name'

If RubySource and DecLiteral are entered normally (not as a string mixin), then the code compiles.


I tried reducing it a bit more:

class ZeroOrMore(Expr)
{
    enum name = "ZeroOrMore!("~Expr.name~")";
}
mixin(q{
	alias ZeroOrMore!(DecLiteral) foo;

	class DecLiteral
	{
		enum name = "Range!("~begin~","~end~")";
	}
});
void main() {
}

However, then I get a *large* number of errors:

dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'name'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'opDot'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'opDispatch'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'ame'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'nme'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'nae'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'nam'
dmd_crash.d(32): Error: class dmd_crash.DecLiteral is forward referenced when looking for 'anme'
...

For thousands of lines. I waited a little while, then killed dmd. Both of these examples are valid code, right?
Comment 1 Kenji Hara 2013-11-22 00:27:30 UTC
(In reply to comment #0)
> Hi, I was working on a grammar with Pegged and dmd crashed. I reduced it to:
> 
> class ZeroOrMore(Expr)
> {
>     enum name = "ZeroOrMore!("~Expr.name~")";
> }
> class Range(char begin, char end)
> {
>     enum name = "Range!("~begin~","~end~")";
> }
> mixin(q{
>     class RubySource : ZeroOrMore!(DecLiteral)
>     {
>     }
>     class DecLiteral : Range!('0','9')
>     {
>     }
> });
> void main() {
> }
> 
> I get this error, followed by dmd crashing:
> 
> dmd_crash.d(13): Error: class dmd_crash.DecLiteral is forward referenced when
> looking for 'name'

With git head, crash does not occur anymore. However compilation still wrongly fails.

https://github.com/D-Programming-Language/dmd/pull/2853
Comment 2 github-bugzilla 2013-11-23 21:34:50 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b99f712f40ef15f94facceb4e7ee26bc8ba339a0
fix Issue 7744 - Forward reference in string mixin

https://github.com/D-Programming-Language/dmd/commit/69dcaa99041925877006636f244fd7e814781d92
Merge pull request #2853 from 9rnsr/fix7744

Issue 7744 - Forward reference in string mixin