summaryrefslogtreecommitdiffstats
path: root/tests/bugs/ptr-extension-this-type.slang
blob: 627db53027e0ea1b418537be12a760322d77df08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//TEST:INTERPRET(filecheck=CHECK):

// Test for issue #7656: Compiler segfault with Ptr<T> extension referring to This
// This test ensures that the compiler doesn't segfault when 'This' is used in Ptr<T> extensions

public interface IThing
{
    int f(This other);
}

public extension Ptr<int>: IThing
{
    public int f(This other)
    {
        // Test that 'This' refers to Ptr<int>, not the pointed-to type int
        return sizeof(This) - sizeof(Ptr<int>) + 1;
    }
}

void main()
{
    Ptr<int> p;
    Ptr<int> other;
    int result = p.f(other);
    
    // CHECK: 1
    printf("%d\n", result);
}