Bug 12228 – Identifiers 'this' and 'super' should not be allowed as base classes

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-22T13:56:51Z
Last change time
2019-12-17T17:52:50Z
Keywords
pull, spec
Assigned to
Andrej Mitrovic
Creator
Andrej Mitrovic
See also
https://issues.dlang.org/show_bug.cgi?id=18228, https://issues.dlang.org/show_bug.cgi?id=13130, https://issues.dlang.org/show_bug.cgi?id=13943, https://issues.dlang.org/show_bug.cgi?id=14170, https://issues.dlang.org/show_bug.cgi?id=6579

Comments

Comment #0 by andrej.mitrovich — 2014-02-22T13:56:51Z
----- class A { static class B : this { } } void main() { } ----- The above is expressible via ": typeof(this)", allowing " : this" doesn't make too much sense to me.
Comment #1 by devw0rp — 2014-02-22T14:10:42Z
I thought of doing this now while writing my SMOKE generator which spits out D source files. I'm not sure if this is bad to have in the language. If I can use one or the other I'll be happy.
Comment #2 by yebblies — 2014-02-22T19:07:01Z
Likely because of issue 2540, which I think was probably a mistake.
Comment #3 by andrej.mitrovich — 2014-04-27T10:58:30Z
Comment #4 by bugzilla — 2014-04-28T01:59:07Z
The Issue 2540 definitely introduced this. Looking back on it, 2540 was probably a bad idea, but I think we're stuck with it. Trying to step on its other effects just seems to complicate things even more. I suggest just leaving this one alone.
Comment #5 by bugzilla — 2014-05-02T22:19:37Z
let's go the documentation route, i.e. simply document the behavior
Comment #6 by r.sagitario — 2014-08-23T15:02:12Z
Here are some more examples of what is allowed with "this" and "super": class Foo { this(this that, super base) { // this other = that; // static shared(super) s; } void member(this that) { } super base; // this next; shared(this) that; static shared(super) sup; } Commented lines produce an error. See also #13130. Should this be documented, too?
Comment #7 by yebblies — 2015-03-28T03:54:13Z
With issue 14348 fixed, all cases from issue 2540 should be replaceable with typeof(this/super). I think we should seriously consider deprecating and eventually removing this behavior. eg Warning: Using 'this' as a type is deprecated, use 'typeof(this)' instead
Comment #8 by andrei — 2018-04-12T14:00:40Z
The problem here is that "this" and "super" are either data or type, depending (by odd rules) on the context. Let's make that a deprecation and then an error. Thanks.
Comment #9 by slavo5150 — 2018-05-13T02:38:25Z
Comment #10 by nick — 2018-05-14T11:11:25Z
It's great that `this` doesn't work as a type in a parameter list now Issue 18228 is fixed, but `super` should probably be disallowed too: class A { void foo(super i) {} }
Comment #11 by github-bugzilla — 2018-05-31T18:55:44Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/39053127e5d3eaad706f50b60006be966b1b273b Issue 12228 - Deprecate usage of 'this' and 'super' as types https://github.com/dlang/dmd/commit/524a924477fa02bc2ff11de085f93ab657377d0a Merge pull request #8242 from JinShil/fix_12228 Issue 12228 & Issue 13943 - Deprecate usage of 'this' and 'super' as types merged-on-behalf-of: Jacob Carlborg <[email protected]>