Skip to content

Commit 1a74389

Browse files
authored
Merge pull request #182 from zephir-lang/bugfix/issue-82-uchar-cast
Fix: add uchar cast support in xx_ret_type() (issue #82)
2 parents f60725b + b1450ca commit 1a74389

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

parser/parser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ static void xx_ret_type(zval *ret, int type)
624624
parser_get_string(ret, "char");
625625
return;
626626

627+
case XX_TYPE_UCHAR:
628+
parser_get_string(ret, "uchar");
629+
return;
630+
627631
case XX_TYPE_ARRAY:
628632
parser_get_string(ret, "array");
629633
return;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Cast to numeric types (int, uint, char, uchar, long, ulong)
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$types = ['char', 'uchar', 'int', 'uint', 'long', 'ulong'];
8+
foreach ($types as $type) {
9+
$code = "function test() { return ({$type}) foo; }";
10+
$ir = zephir_parse_file($code, '(eval code)');
11+
$expr = $ir[0]["statements"][0]["expr"];
12+
printf("%-6s => type=%s left=%s\n", $type, $expr["type"], $expr["left"]);
13+
}
14+
?>
15+
--EXPECT--
16+
char => type=cast left=char
17+
uchar => type=cast left=uchar
18+
int => type=cast left=int
19+
uint => type=cast left=uint
20+
long => type=cast left=long
21+
ulong => type=cast left=ulong
22+

tests/operators/cast-uchar.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Cast to uchar type (issue #82)
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$code =<<<ZEP
8+
function test() {
9+
return (uchar) foo;
10+
}
11+
ZEP;
12+
13+
$ir = zephir_parse_file($code, '(eval code)');
14+
var_dump($ir[0]["statements"][0]["expr"]);
15+
?>
16+
--EXPECT--
17+
array(6) {
18+
["type"]=>
19+
string(4) "cast"
20+
["left"]=>
21+
string(5) "uchar"
22+
["right"]=>
23+
array(5) {
24+
["type"]=>
25+
string(8) "variable"
26+
["value"]=>
27+
string(3) "foo"
28+
["file"]=>
29+
string(11) "(eval code)"
30+
["line"]=>
31+
int(2)
32+
["char"]=>
33+
int(20)
34+
}
35+
["file"]=>
36+
string(11) "(eval code)"
37+
["line"]=>
38+
int(2)
39+
["char"]=>
40+
int(20)
41+
}
42+

0 commit comments

Comments
 (0)