Bug 12807 – UFCS checks "alias this" attributes even when not called

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-26T19:18:40Z
Last change time
2018-04-23T07:55:43Z
Assigned to
No Owner
Creator
monarchdodra
See also
https://issues.dlang.org/show_bug.cgi?id=18775

Comments

Comment #0 by monarchdodra — 2014-05-26T19:18:40Z
Basically, if you call a function "UFCS style", on an object that has an alias this, then the compiler (from what I can observe) will consider the "alias this" as "called" to evaluate the attributes, even if the alias this is not actually called. Example: //---- void foo(T)(ref T t) { pragma(msg, T.stringof); } struct S { int impure() {assert(0);} alias impure this; } void main() pure { S s; foo(s); //YES s.foo(); //NO } //---- Error: pure function 'D main' cannot call impure function 'main.S.impure' //---- What's "funny" is that is you remove the "pure" on main, we can verify that "impure" is never actually called. Discovered while writing: https://github.com/D-Programming-Language/phobos/pull/2202 Originally: assert(!source.doesPointTo(source), "msg"); Worked around with: assert(!doesPointTo(source, source), "msg");
Comment #1 by github-bugzilla — 2018-04-23T07:55:39Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4de9546b9ddd2ed9c1abda0aac05ebcd97b745fb Add testcase for issue 12807 https://github.com/dlang/dmd/commit/36cdbbffad2f70376ea46bd0b381bbfe586c669a Only emit warnings during alias this resolution if the alias this later actually turns out to lead to a valid property access. Fixes issues 18775, 12807 https://github.com/dlang/dmd/commit/d29d0041e8eee26c8fa3d7b50d4d3714f1e298bb Merge pull request #8194 from FeepingCreature/fix/18775-12807-fail-gently-on-alias-this Fix Issue 18775, 12807: gently resolve alias this