dmd v2.047 shows a compilation error on the call to bar4, but in my opinion the compiler has to compile all four those bar methods: struct Foo { alias typeof(this) typeof_this; void bar1(typeof_this other) {} void bar2()(typeof_this other) {} void bar3(typeof(this) other) {} void bar4()(typeof(this) other) {} } void main() { Foo f; f.bar1(f); // OK f.bar2(f); // OK f.bar3(f); // OK f.bar4(f); // ERR } The generated errors: test.d(13): Error: template test.Foo.bar4() does not match any function template declaration test.d(13): Error: template test.Foo.bar4() cannot deduce template function from argument types !()(Foo) The problem of bar4 has shown up in D2 code similar to this one, where I have used typeof(this) to follow the DRY strategy and avoid repeating the struct name more than one time: struct Vec2 { float x, y; auto opBinary(string op)(typeof(this) other) if (op == "+") { ... } } A workaround that can be used is: struct Vec2 { float x, y; alias typeof(this) typeof_this; auto opBinary(string op)(typeof_this other) if (op == "+") { ... } }
Calling semantic on the param type in ::deduceType seems to be simplest workaround without causing side effects. --- a/src/template.c +++ b/src/template.c @@ -2183,6 +2183,7 @@ MATCH TypeStruct::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame * to a template instance, too, and try again. */ TemplateInstance *ti = sym->parent->isTemplateInstance(); + tparam = tparam->semantic(0, sc); if (tparam && tparam->ty == Tinstance) { @@ -2317,6 +2318,7 @@ MATCH TypeClass::deduceType(Scope *sc, Type *tparam, TemplateParameters *paramet * to a template instance, too, and try again. */ TemplateInstance *ti = sym->parent->isTemplateInstance(); + tparam = tparam->semantic(0, sc); if (tparam && tparam->ty == Tinstance) { Ideally though, all typeof()'s should have been expanded beforehand. Regards
*** Issue 5532 has been marked as a duplicate of this issue. ***
The patch by Iain seems to break std.datetime: /usr/local/include/d2/std/datetime.d(9217): Error: template instance std.datetime.DTRebindable!(immutable(TimeZone)) error instantiating
(In reply to comment #3) > The patch by Iain seems to break std.datetime: > > /usr/local/include/d2/std/datetime.d(9217): Error: template instance > std.datetime.DTRebindable!(immutable(TimeZone)) error instantiating Yep, I was merely suggesting that things should ideally be worked out before this point (because they *can* be worked out).
*** Issue 5801 has been marked as a duplicate of this issue. ***
https://github.com/D-Programming-Language/dmd/pull/572
https://github.com/D-Programming-Language/dmd/commit/8fa99fca73fea3a5130939ecaa83596f925cdbb8 https://github.com/D-Programming-Language/dmd/commit/2324c9903f99bb355ac5b2f25298a4f05ab0fba1
*** Issue 5903 has been marked as a duplicate of this issue. ***
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル