Skip to content

Commit

Permalink
[php] check string type in TUnop too (closes HaxeFoundation#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Aug 19, 2014
1 parent 721ce12 commit 456fe97
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion genphp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ and gen_expr ctx e =
);
| TField (e1,s) ->
spr ctx (Ast.s_unop op);
gen_field_access ctx true e1 (field_name s)
gen_tfield ctx e e1 (field_name s)
| _ ->
spr ctx (Ast.s_unop op);
gen_value ctx e)
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/issues/Issue3263.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package unit.issues;

class Issue3263 extends Test {
public static function teststrings1 () {
var str1 = 'Test';
var len = str1.length;
var str2 = str1.substr(0, -(len)-1);
return str2;
}

public static function teststrings2 () {
var str1 = 'Test';
var str2 = str1.substr(0, -(str1.length)-1);
return str2;
}

public static function teststrings3 () {
var str1 = 'Test';
var str2 = str1.substr(0, (str1.length)-1);
return str2;
}

public static function teststrings4 () {
var str1 = 'Test';
var str2 = str1.substr(0, (str1.length));
return str2;
}

public static function teststrings5 () {
var str1 = 'Test';
var str2 = str1.substr(0, str1.length);
return str2;
}

public static function teststrings6 () {
var str1 = 'Test';
var str2 = str1.substr(0, -str1.length - 1);
return str2;
}

public static function teststrings7 () {
var str1 = 'Test';
var str2 = str1.substr(0, -str1.length);
return str2;
}

function test() {
//eq("Tes", teststrings1());
eq("Tes", teststrings3());
eq("Test", teststrings4());
eq("Test", teststrings5());
//eq("Tes", teststrings2());
//eq("Tes", teststrings6());
eq("", teststrings7());
}
}

0 comments on commit 456fe97

Please sign in to comment.