1414 Variable
1515};
1616use lang \ast \syntax \Extension ;
17- use lang \ast \types \{IsArray , IsLiteral };
17+ use lang \ast \types \{IsArray , IsLiteral , IsValue };
1818
1919class Records implements Extension {
2020
@@ -26,30 +26,26 @@ public static function inject(&$type, $name, $signature, $body) {
2626
2727 public function setup ($ language , $ emitter ) {
2828 $ language ->stmt ('record ' , function ($ parse , $ token ) {
29- $ type = $ parse ->scope ->resolve ($ parse ->token ->value );
30- $ parse ->forward ();
31-
3229 $ comment = $ parse ->comment ;
33- $ parse ->comment = null ;
3430 $ line = $ parse ->token ->line ;
31+ $ parse ->comment = null ;
3532
33+ $ type = $ this ->type ($ parse , false );
3634 $ parse ->expecting ('( ' , 'record ' );
3735 $ components = $ this ->parameters ($ parse , []);
3836 $ parse ->expecting (') ' , 'record ' );
3937
4038 $ parent = null ;
4139 if ('extends ' === $ parse ->token ->value ) {
4240 $ parse ->forward ();
43- $ parent = $ parse ->scope ->resolve ($ parse ->token ->value );
44- $ parse ->forward ();
41+ $ parent = $ this ->type ($ parse , false );
4542 }
4643
4744 $ implements = [];
4845 if ('implements ' === $ parse ->token ->value ) {
4946 $ parse ->forward ();
5047 do {
51- $ implements []= $ parse ->scope ->resolve ($ parse ->token ->value );
52- $ parse ->forward ();
48+ $ implements []= $ this ->type ($ parse , false );
5349 if (', ' === $ parse ->token ->value ) {
5450 $ parse ->forward ();
5551 } else if ('{ ' === $ parse ->token ->value ) {
@@ -136,6 +132,7 @@ public function setup($language, $emitter) {
136132 self ::inject ($ body , 'compareTo ' , new Signature ([new Parameter ('value ' , null )], new IsLiteral ('int ' )), new Code (
137133 '$value instanceof self ? \\util \\Objects::compare([ ' .substr ($ object , 2 ).'], [ ' .substr ($ value , 2 ).']) : 1 '
138134 ));
135+ $ node ->implements []= new IsValue ('\\lang \\Value ' );
139136
140137 // Add decomposition
141138 self ::inject ($ body , '__invoke ' , new Signature ([new Parameter ('map ' , new IsLiteral ('callable ' ), new Literal ('null ' ))], null ), new Code (
@@ -146,7 +143,7 @@ public function setup($language, $emitter) {
146143 ['final ' ],
147144 $ node ->name ,
148145 $ node ->parent ,
149- array_merge ([ '\\ lang \\ Value ' ], $ node ->implements ) ,
146+ $ node ->implements ,
150147 $ body ,
151148 $ node ->annotations ,
152149 $ node ->comment ,
0 commit comments