|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of sdl package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Railt\SDL\Frontend\Ast\Definition\Common; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\NodeInterface; |
|
13
|
|
|
use Railt\Parser\Ast\Rule; |
|
14
|
|
|
use Railt\Parser\Ast\RuleInterface; |
|
15
|
|
|
use Railt\SDL\IR\TypeHint; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class TypeHintNode |
|
19
|
|
|
*/ |
|
20
|
|
|
class TypeHintNode extends Rule |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var TypeHint |
|
24
|
|
|
*/ |
|
25
|
|
|
private $hint; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* TypeHintNode constructor. |
|
29
|
|
|
* @param string $name |
|
30
|
|
|
* @param array $children |
|
31
|
|
|
* @param int $offset |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(string $name, array $children = [], int $offset = 0) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($name, $children, $offset); |
|
36
|
|
|
|
|
37
|
|
|
$this->hint = new TypeHint(); |
|
38
|
|
|
|
|
39
|
|
|
foreach ($this->analyze($this->getChild(0)) as $child) { |
|
|
|
|
|
|
40
|
|
|
switch ($child) { |
|
41
|
|
|
case 'List': |
|
42
|
|
|
$this->hint->withModifiers(TypeHint::IS_LIST); |
|
43
|
|
|
break; |
|
44
|
|
|
|
|
45
|
|
|
case 'NonNull': |
|
46
|
|
|
$modifier = $this->hint->isList() |
|
47
|
|
|
? TypeHint::IS_LIST_OF_NOT_NULL |
|
48
|
|
|
: TypeHint::IS_NOT_NULL; |
|
49
|
|
|
|
|
50
|
|
|
$this->hint->withModifiers($modifier); |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param RuleInterface|NodeInterface $rule |
|
58
|
|
|
* @return \Generator |
|
59
|
|
|
*/ |
|
60
|
|
|
private function analyze(RuleInterface $rule): \Generator |
|
61
|
|
|
{ |
|
62
|
|
|
$name = $rule->getName(); |
|
63
|
|
|
|
|
64
|
|
|
if ($name !== 'TypeName') { |
|
65
|
|
|
yield $name; |
|
66
|
|
|
yield from $this->analyze($rule->getChild(0)); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return int |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getModifiers(): int |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->hint->getModifiers(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: