Skip to content

Commit

Permalink
fix Issue 22133 - [REG2.097] Breaking change in DotTemplateExp type s…
Browse files Browse the repository at this point in the history
…emantics leading to e.g. isInputRange regression
  • Loading branch information
ibuclaw authored and dlang-bot committed Jul 21, 2021
1 parent a5c1124 commit f9e8117
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -4742,6 +4742,18 @@ extern (C++) final class DotTemplateExp : UnaExp
this.td = td;
}

override bool checkType()
{
error("%s `%s` has no type", td.kind(), toChars());
return true;
}

override bool checkValue()
{
error("%s `%s` has no value", td.kind(), toChars());
return true;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
2 changes: 2 additions & 0 deletions src/dmd/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ class DotTemplateExp : public UnaExp
public:
TemplateDeclaration *td;

bool checkType();
bool checkValue();
void accept(Visitor *v) { v->visit(this); }
};

Expand Down
2 changes: 2 additions & 0 deletions src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,8 @@ class DotTemplateExp final : public UnaExp
{
public:
TemplateDeclaration* td;
bool checkType();
bool checkValue();
void accept(Visitor* v);
};

Expand Down
16 changes: 16 additions & 0 deletions test/compilable/test22133.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://issues.dlang.org/show_bug.cgi?id=22133

struct Slice
{
bool empty() const;
int front() const;
void popFront()() // note: requires a mutable Slice
{}
}

enum isInputRange1(R) = is(typeof((R r) => r.popFront));
enum isInputRange2(R) = __traits(compiles, (R r) => r.popFront);
static assert(isInputRange1!( Slice) == true);
static assert(isInputRange1!(const Slice) == false);
static assert(isInputRange2!( Slice) == true);
static assert(isInputRange2!(const Slice) == false);
24 changes: 24 additions & 0 deletions test/fail_compilation/fail22133.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://issues.dlang.org/show_bug.cgi?id=22133
/*
TEST_OUTPUT
---
fail_compilation/fail22133.d(16): Error: `s.popFront()()` has no effect
fail_compilation/fail22133.d(17): Error: template `s.popFront()()` has no type
---
*/
struct Slice
{
void popFront()() {}
}

auto fail22133(const Slice s)
{
s.popFront;
return s.popFront;
}

auto ok22133(Slice s)
{
s.popFront;
return s.popFront;
}
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424b.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424b.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424b.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424b
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424c.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424c.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424c.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424c
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424d.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424d.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424d.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424d
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424e.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424e.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424e.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424e
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424f.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424f.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424f.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424f
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424g.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424g.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424g.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424g
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424h.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424h.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424h.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424g
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail7424i.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7424i.d(10): Error: expression `this.g()()` is `void` and has no value
fail_compilation/fail7424i.d(10): Error: template `this.g()()` has no value
---
*/
struct S7424g
Expand Down

0 comments on commit f9e8117

Please sign in to comment.