@@ -295,18 +295,19 @@ export function assignFn(
295295
296296 if ( isOperatorDef ( def ) ) {
297297 const value = assignValueAsValue ( ce , arg2 ) ;
298- if ( value ) throw Error ( `Cannot change the operator "${ id } " to a value` ) ;
298+ if ( value !== undefined ) {
299+ // Allow converting an operator to a value.
300+ // Existing expressions using this symbol as a function head (e.g.
301+ // ["g", 2]) will produce a type error at evaluation time if the
302+ // new value is not callable — which is the correct semantic.
303+ updateDef ( ce , id , def , { value } ) ;
304+ ce . _setSymbolValue ( id , value ) ;
305+ return ce ;
306+ }
299307
300308 // Update the operator definition.
301- // Note: this is a potentially dangerous operation, since the
302- // operator may be used in other expressions that are not
303- // re-canonicalized. However, it might be desirable to override the
304- // evaluation of an operator in a specific context, even a system
305- // operator.
306- // However, it is preferable to use `ce.declare()` to create a new
307- // operator.
308309 const fnDef = assignValueAsOperatorDef ( ce , arg2 ) ;
309- if ( ! fnDef ) throw Error ( `Cannot change the operator "${ id } " to a value ` ) ;
310+ if ( ! fnDef ) throw Error ( `Invalid definition for symbol "${ id } "` ) ;
310311 updateDef ( ce , id , def , fnDef ) ;
311312 return ce ;
312313 }
0 commit comments