Issue 20277 - Template this parameters are not respected in static context
Summary: Template this parameters are not respected in static context
Status: RESOLVED DUPLICATE of issue 10488
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
: 20816 (view as issue list)
Depends on:
Blocks:
 
Reported: 2019-10-07 11:48 UTC by Max Samukha
Modified: 2022-09-14 13:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2019-10-07 11:48:45 UTC
class A {
    void foo(this T)() {
    }
    
    static void bar(this T)() {
    }
    
    template baz(this T) {
        static void baz() {
        }
    }
}

class B : A {
}

void main()
{   
    B b; 
    b.foo(); // ok
  	
    B.bar(); //fail
    b.bar(); // fail
    
    b.baz(); // ok
    B.baz(); // fail
}

onlineapp.d(22): Error: template onlineapp.A.bar cannot deduce function from argument types !()(), candidates are:
onlineapp.d(5):        bar(this T)()
onlineapp.d(23): Error: template onlineapp.A.bar cannot deduce function from argument types !()(), candidates are:
onlineapp.d(5):        bar(this T)()
onlineapp.d(26): Error: template onlineapp.A.baz cannot deduce function from argument types !()(), candidates are:
onlineapp.d(8):        baz(this T)()

run.dlang.io: https://run.dlang.io/is/Hme9vp

Accessing the static type of a class in the context of a base class is an extremely useful feature, and there is no reason to restrict it to just non-static functions, precluding valid use cases like factory function generation etc.
Comment 1 Max Samukha 2020-05-10 16:25:42 UTC
*** Issue 20816 has been marked as a duplicate of this issue. ***
Comment 2 Adam D. Ruppe 2020-05-10 17:00:19 UTC
in the duplicate i argue from the spec that this should work too
Comment 3 Nick Treleaven 2022-09-14 13:26:32 UTC

*** This issue has been marked as a duplicate of issue 10488 ***