@@ -90,31 +90,44 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
9090 $ constructor = $ action ['stored_constructor ' ];
9191
9292 $ names = $ this ->storedNames ;
93+ $ flags = [];
9394 if ($ this ->storedFlags ) {
95+ foreach ($ names as $ name => $ type ) {
96+ if (str_starts_with ($ type , 'flags. ' )) {
97+ $ flags [$ name ] = $ type ;
98+ }
99+ }
94100 $ names = [
95101 'flags ' => '# ' ,
96102 ...$ names
97103 ];
98104 }
99105
100106 if (isset ($ this ->outputSchema [$ constructor ])) {
101- foreach ($ this ->outputSchema [$ constructor ] as $ name => $ type ) {
107+ $ existing = $ this ->outputSchema [$ constructor ];
108+ foreach ($ existing as $ name => $ type ) {
109+ if (str_starts_with ($ type , 'flags. ' )) {
110+ if (isset ($ flags [$ name ])) {
111+ unset($ flags [$ name ], $ names [$ name ]);
112+ }
113+ }
114+ }
115+ if ($ flags ) {
116+ throw new AssertionError ("Have leftover flags: " .implode (' ' , $ flags ));
117+ }
118+ foreach ($ existing as $ name => $ type ) {
102119 if (isset ($ names [$ name ])) {
103120 if ($ names [$ name ] === $ type ) {
104121 unset($ names [$ name ]);
105122 } else {
106123 throw new AssertionError ("Type mismatch for $ constructor. $ name: have {$ names [$ name ]}, need $ type " );
107124 }
108- } else if (str_starts_with ($ type , 'flags. ' )) {
109- if ($ this ->storedFlags ) {
110- throw new AssertionError ("Have conflicting flag $ constructor. $ name: $ type; new schema is " .self ::stringifySchema ($ constructor , $ names ));
111- }
112- } elseif ($ name !== 'flags ' ) {
125+ } elseif (!str_starts_with ($ type , 'flags. ' ) && $ name !== 'flags ' ) {
113126 throw new AssertionError ("Missing pre-existing parameter $ constructor. $ name for $ constructor " );
114127 }
115128 }
116129 foreach ($ names as $ name => $ type ) {
117- throw new AssertionError ("Leftover parameter $ constructor. $ name: $ type for $ constructor" );
130+ throw new AssertionError ("Leftover parameter $ constructor. $ name: $ type for " . self :: stringifySchema ( $ constructor, $ existing ) );
118131 }
119132 } else {
120133 $ this ->outputSchema [$ constructor ] = $ names ;
0 commit comments