@@ -1292,31 +1292,37 @@ function setupProgramBlocks(activity) {
12921292 i < activity . blocks . protoBlockDict [ protoblk ] . dockTypes . length ;
12931293 i ++
12941294 ) {
1295- // FIXME: type check args
1295+ // Type check and handle args
12961296 if ( i < blockArgs . length ) {
1297- if ( typeof blockArgs [ i ] === "number" ) {
1298- if (
1299- ! [ "anyin" , "numberin" ] . includes (
1300- activity . blocks . protoBlockDict [ protoblk ] . dockTypes [ i ]
1301- )
1302- ) {
1297+ const arg = blockArgs [ i ] ;
1298+ const dockType = activity . blocks . protoBlockDict [ protoblk ] . dockTypes [ i ] ;
1299+
1300+ if ( typeof arg === "number" ) {
1301+ if ( ! [ "anyin" , "numberin" ] . includes ( dockType ) ) {
1302+ activity . errorMsg ( _ ( "Warning: block argument type mismatch" ) ) ;
1303+ }
1304+ newBlock . push ( [ i , [ "number" , { value : arg } ] , 0 , 0 , [ 0 ] ] ) ;
1305+ newBlock [ 0 ] [ 4 ] . push ( i ) ;
1306+ } else if ( typeof arg === "string" ) {
1307+ if ( ! [ "anyin" , "textin" ] . includes ( dockType ) ) {
13031308 activity . errorMsg ( _ ( "Warning: block argument type mismatch" ) ) ;
13041309 }
1305- newBlock . push ( [ i , [ "number" , { value : blockArgs [ i ] } ] , 0 , 0 , [ 0 ] ] ) ;
1306- } else if ( typeof blockArgs [ i ] === "string" ) {
1307- if (
1308- ! [ "anyin" , "textin" ] . includes (
1309- activity . blocks . protoBlockDict [ protoblk ] . dockTypes [ i ]
1310- )
1311- ) {
1310+ newBlock . push ( [ i , [ "string" , { value : arg } ] , 0 , 0 , [ 0 ] ] ) ;
1311+ newBlock [ 0 ] [ 4 ] . push ( i ) ;
1312+ } else if ( typeof arg === "boolean" ) {
1313+ if ( ! [ "anyin" , "booleanin" ] . includes ( dockType ) ) {
13121314 activity . errorMsg ( _ ( "Warning: block argument type mismatch" ) ) ;
13131315 }
1314- newBlock . push ( [ i , [ "string" , { value : blockArgs [ i ] } ] , 0 , 0 , [ 0 ] ] ) ;
1316+ newBlock . push ( [ i , [ "boolean" , { value : arg } ] , 0 , 0 , [ 0 ] ] ) ;
1317+ newBlock [ 0 ] [ 4 ] . push ( i ) ;
13151318 } else {
1319+ activity . errorMsg (
1320+ _ ( "Warning: block argument type unhandled: " ) + typeof arg
1321+ ) ;
1322+ // eslint-disable-next-line no-console
1323+ console . warn ( "Unhandled argument type" , arg ) ;
13161324 newBlock [ 0 ] [ 4 ] . push ( null ) ;
13171325 }
1318-
1319- newBlock [ 0 ] [ 4 ] . push ( i ) ;
13201326 } else {
13211327 newBlock [ 0 ] [ 4 ] . push ( null ) ;
13221328 }
0 commit comments