digitalmars.D.learn - Is this a bug?
- Eric (29/29) Apr 15 2016 1 alias J = const C;
- ag0aep6g (5/33) Apr 15 2016 Line 6 isn't accepted either. If you remove the constraint, the compiler...
- Eric (4/27) Apr 15 2016 Thanks. I see that now. Is there any way I can make the compiler
- Eric (3/34) Apr 15 2016 line 6 can be fixed like this: "const I!(J) i = a;"
- Eric (20/22) Apr 15 2016 This works:
- ag0aep6g (5/7) Apr 15 2016 A little tip: You can omit the parentheses of template instantiations
- Jonathan M Davis via Digitalmars-d-learn (8/11) Apr 15 2016 It's definitely ignored, and I'd argue that it's a bug in the compiler t...
1 alias J = const C;
2
3 void main(string[] args)
4 {
5 J a = new C();
6 I!(J) i = a;
7 }
8
9 interface I(V) { }
10
11 class F(V) if (is(V : I!(V))) { }
12
13 class C : I!(J)
14 {
15 F!(J) m;
16 }
The above code gives the following compile error:
Error:
template instance F!(const(C)) does not match template
declaration F(V) if (is(V : I!V))
on line 15.
If I change line 1 to "alias J = C;" the code will compile. The
problem seems to be
the template constraint on line 11. I think the constraint says,
"If V can be automatically
converted to I!(V) then this template can be used". However,
line 6 does not give
an error, and it seems to be automaticaly converting J to I!(J).
-Eric
Apr 15 2016
On 15.04.2016 19:13, Eric wrote:
1 alias J = const C;
2
3 void main(string[] args)
4 {
5 J a = new C();
6 I!(J) i = a;
7 }
8
9 interface I(V) { }
10
11 class F(V) if (is(V : I!(V))) { }
12
13 class C : I!(J)
14 {
15 F!(J) m;
16 }
The above code gives the following compile error:
Error:
template instance F!(const(C)) does not match template declaration F(V)
if (is(V : I!V))
on line 15.
If I change line 1 to "alias J = C;" the code will compile. The problem
seems to be
the template constraint on line 11. I think the constraint says, "If V
can be automatically
converted to I!(V) then this template can be used". However, line 6
does not give
an error, and it seems to be automaticaly converting J to I!(J).
Line 6 isn't accepted either. If you remove the constraint, the compiler
complains about it. So it's just the next error in line.
And really const C can't be converted to I!(const C) implicitly. The
former is const, the latter is mutable => no go.
Apr 15 2016
On Friday, 15 April 2016 at 17:43:59 UTC, ag0aep6g wrote:On 15.04.2016 19:13, Eric wrote:Thanks. I see that now. Is there any way I can make the compiler understand that the interface is const? -Eric1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : I!(V))) { } 12 13 class C : I!(J) 14 { 15 F!(J) m; 16 }Line 6 isn't accepted either. If you remove the constraint, the compiler complains about it. So it's just the next error in line. And really const C can't be converted to I!(const C) implicitly. The former is const, the latter is mutable => no go.
Apr 15 2016
On Friday, 15 April 2016 at 18:22:02 UTC, Eric wrote:On Friday, 15 April 2016 at 17:43:59 UTC, ag0aep6g wrote:line 6 can be fixed like this: "const I!(J) i = a;" Now if I can just figure out how to fix line 15...On 15.04.2016 19:13, Eric wrote:Thanks. I see that now. Is there any way I can make the compiler understand that the interface is const? -Eric1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : I!(V))) { } 12 13 class C : I!(J) 14 { 15 F!(J) m; 16 }Line 6 isn't accepted either. If you remove the constraint, the compiler complains about it. So it's just the next error in line. And really const C can't be converted to I!(const C) implicitly. The former is const, the latter is mutable => no go.
Apr 15 2016
On Friday, 15 April 2016 at 18:28:58 UTC, Eric wrote:line 6 can be fixed like this: "const I!(J) i = a;" Now if I can just figure out how to fix line 15...This works: 1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 const (I!(J)) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : const(I!(V)))) { } 12 13 class C : const (I!(J)) 14 { 15 F!(J) m; 16 } 17 -Eric
Apr 15 2016
On 15.04.2016 20:55, Eric wrote:13 class C : const (I!(J))I think this const is ignored by the compiler.15 F!(J) m;A little tip: You can omit the parentheses of template instantiations when the argument is a single identifier. That is, `F!(J)` can be written as `F!J`.
Apr 15 2016
On Saturday, April 16, 2016 00:28:46 ag0aep6g via Digitalmars-d-learn wrote:On 15.04.2016 20:55, Eric wrote:It's definitely ignored, and I'd argue that it's a bug in the compiler that it's even accepted. There's no such thing as a const or immutable class - just a const or immutable instance of a class. Member functions of a class can be const or immutable but not the class itself. Doing so is just equivalent to marking every function in the class as const or immutable. Deriving from a const or immutable class is nonsense. - Jonathan M Davis13 class C : const (I!(J))I think this const is ignored by the compiler.
Apr 15 2016








Jonathan M Davis via Digitalmars-d-learn