Skip to content

Commit

Permalink
Merge pull request #2339 from donc/fourCTFEtestcases
Browse files Browse the repository at this point in the history
Test cases for bugs 1982, 7988, 8253, and 8285.
  • Loading branch information
andralex committed Jul 12, 2013
2 parents 8db6add + f5c5d43 commit a0ba3b2
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,85 @@ static assert(!is(typeof(compiles!(rshr10252(80)))));
static assert(is(typeof(compiles!(ushr10252(2)))));
static assert(!is(typeof(compiles!(ushr10252(60)))));

/**************************************************
1982 CTFE null problems
**************************************************/

enum a1982 = [1, 2, 3];
static assert (a1982 !is null);

string foo1982() { return null; }
static assert (foo1982() is null);
static assert (!foo1982().length);

static assert (null is null);

/**************************************************
7988 CTFE return values should be allowed in compile-time expressions
**************************************************/

class X7988 { int y; this() { y = 2; }}
static assert( (new X7988).y == 2);

/**************************************************
8253 ICE: calling of member function of non-CTFE class variable
**************************************************/

class Bug8253 {
bool j(){
return true;
}
}
Bug8253 m8253;
static assert(!is(typeof(compiles!(m8253.j()))));

/**************************************************
8285 Issue with slice returned from CTFE function
**************************************************/

string foo8285() {
string s = "ab";
return s[0 .. $];
}

template T8285b(string s) { }

template T8285a() {
enum s = foo8285();
alias T8285b!(s) t2;
}

int bar8285() {
alias T8285a!() t1;
return 0;
}

int baz8285(int x) {
return 0;
}

static assert(baz8285(bar8285()) == 0);

// test case 2

string xbar8285() {
string s = "ab";
return s[0..$];
}

template xT8285a() {
enum xT8285a = xbar8285()[0..$];
}

string xbaz8285() {
return xT8285a!();
}

string xfoo8285(string s) {
return s;
}

static assert(xfoo8285(xbaz8285()) == "ab");

/**************************************************
'this' parameter bug revealed during refactoring
Expand Down

0 comments on commit a0ba3b2

Please sign in to comment.