D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13408 - template mixins allows to declare duplicates
Summary: template mixins allows to declare duplicates
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-31 11:07 UTC by Temtaime
Modified: 2024-12-13 18:25 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Temtaime 2014-08-31 11:07:45 UTC
import std.stdio;

mixin template R() {
	~this() { write(1); }
}

struct S {
	mixin R;

	~this() { write(2); }
}

void main() {
	S s;
}

This code compiles OK and prints 21 when it should NOT.

import std.stdio;

mixin template R() {
	int a = 1;
	void foo() { write(a); }
}

struct S {
	mixin R;

	void bar() { write(a); }

	int a = 2;
}

void main() {
	S s;
	s.foo();
	s.bar();
}

This code also compiles OK and prints 12 when it's strange and bug-prone.
Comment 1 Temtaime 2014-09-01 11:50:45 UTC
There's one another issue.

mixin template R() {
	void foo() { writeln(1); }
	void foo() { writeln(2); }
}

struct S {
	mixin R;
}

void main() {
	S s;
}

This code compiles OK, but linker error.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:25:23 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18876

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB