Bug 14128 – AliasDeclaration allows expressions, causing false code for ThisExp

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-06T03:50:18Z
Last change time
2024-12-13T18:39:59Z
Keywords
accepts-invalid, pull, wrong-code
Assigned to
No Owner
Creator
Vlad Levenfeld
See also
https://issues.dlang.org/show_bug.cgi?id=19786, https://issues.dlang.org/show_bug.cgi?id=16123
Moved to GitHub: dmd#18942 →

Comments

Comment #0 by vlevenfeld — 2015-02-06T03:50:18Z
The line "alias b = that.object" seems to alias this.object: struct TrivialFunctor (T) { T object; int opCmp ()(auto ref TrivialFunctor!T that) { alias a = this.object; alias b = that.object; import std.stdio; writeln (this.object, ` < `, that.object); // 1 < 2 writeln (a, ` < `, b); // 1 < 1 writeln (&(this.object) == &(that.object)); // false, ok writeln (&a == &b); // true?! stdout.flush; if (a < b) return -1; else if (a > b) return 1; else return 0; } auto opBinary (string op)(auto ref TrivialFunctor!T that) { return TrivialFunctor (mixin(q{this.object } ~ op ~ q{ that.object})); } } auto trivial_functor (T)(T value) { return TrivialFunctor!T (value); } void main () { TrivialFunctor!int a = 1.trivial_functor, b = 2.trivial_functor; auto c = a + b; assert (a < b && b < c); // fails }
Comment #1 by b2.temp — 2020-05-24T08:01:04Z
reduced a bit: --- struct Foo { int v; void test(Foo that) const { alias a = this.v; alias b = that.v; assert (&a !is &b); } } void main () { Foo a = Foo(1); Foo b = Foo(2); a.test(b); } --- The problem is that `that.v` is an expression and this should not be allowed as alias RHS. The compiler think that the current `this` is also the one required for `that`.
Comment #2 by b2.temp — 2020-05-24T08:06:20Z
*** Issue 19786 has been marked as a duplicate of this issue. ***
Comment #3 by dlang-bot — 2020-06-24T01:52:39Z
@NilsLankila updated dlang/dmd pull request #11273 "fix issue 3546 - Support for alias of individual array elements" fixing this issue: - allow alias of member variables and functions by the way, fix issue 14128 https://github.com/dlang/dmd/pull/11273
Comment #4 by nick — 2023-11-21T20:58:34Z
These declarations all alias the same symbol: alias a = this.v; alias b = that.v; alias c = Foo.v; alias d = v; `a` and `b` resolve at compile-time to `v` based on the *type* of `this` (or `that`). The use of an alias of `v` then resolves at runtime to `this.v`. I agree that `a` and `b` look like they are binding to runtime fields.
Comment #5 by dlang-bot — 2023-11-25T18:41:24Z
@ntrel created dlang/dmd pull request #15863 "Fix Issue 14128 - AliasDeclaration allows expressions, causing false …" fixing this issue: - Fix Issue 14128 - AliasDeclaration allows expressions, causing false code for ThisExp https://github.com/dlang/dmd/pull/15863
Comment #6 by robert.schadek — 2024-12-13T18:39:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18942 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB