@@ -861,8 +861,8 @@ impl Node<MemberExpression> {
861861 } ;
862862
863863 // Check the property and object match -- e.g. ints for arrays, strs for objects.
864- match ( object, property) {
865- ( KclValue :: Object { value : map, meta : _ } , Property :: String ( property) ) => {
864+ match ( object, property, self . computed ) {
865+ ( KclValue :: Object { value : map, meta : _ } , Property :: String ( property) , false ) => {
866866 if let Some ( value) = map. get ( & property) {
867867 Ok ( value. to_owned ( ) )
868868 } else {
@@ -872,7 +872,11 @@ impl Node<MemberExpression> {
872872 } ) )
873873 }
874874 }
875- ( KclValue :: Object { .. } , p) => {
875+ ( KclValue :: Object { .. } , Property :: String ( property) , true ) => Err ( KclError :: Semantic ( KclErrorDetails {
876+ message : format ! ( "Cannot index object with string; use dot notation instead, e.g. `obj.{property}`" ) ,
877+ source_ranges : vec ! [ self . clone( ) . into( ) ] ,
878+ } ) ) ,
879+ ( KclValue :: Object { .. } , p, _) => {
876880 let t = p. type_name ( ) ;
877881 let article = article_for ( t) ;
878882 Err ( KclError :: Semantic ( KclErrorDetails {
@@ -885,6 +889,7 @@ impl Node<MemberExpression> {
885889 (
886890 KclValue :: MixedArray { value : arr, .. } | KclValue :: HomArray { value : arr, .. } ,
887891 Property :: UInt ( index) ,
892+ _,
888893 ) => {
889894 let value_of_arr = arr. get ( index) ;
890895 if let Some ( value) = value_of_arr {
@@ -896,7 +901,7 @@ impl Node<MemberExpression> {
896901 } ) )
897902 }
898903 }
899- ( KclValue :: MixedArray { .. } | KclValue :: HomArray { .. } , p) => {
904+ ( KclValue :: MixedArray { .. } | KclValue :: HomArray { .. } , p, _ ) => {
900905 let t = p. type_name ( ) ;
901906 let article = article_for ( t) ;
902907 Err ( KclError :: Semantic ( KclErrorDetails {
@@ -906,10 +911,10 @@ impl Node<MemberExpression> {
906911 source_ranges : vec ! [ self . clone( ) . into( ) ] ,
907912 } ) )
908913 }
909- ( KclValue :: Solid { value } , Property :: String ( prop) ) if prop == "sketch" => Ok ( KclValue :: Sketch {
914+ ( KclValue :: Solid { value } , Property :: String ( prop) , false ) if prop == "sketch" => Ok ( KclValue :: Sketch {
910915 value : Box :: new ( value. sketch ) ,
911916 } ) ,
912- ( KclValue :: Sketch { value : sk } , Property :: String ( prop) ) if prop == "tags" => Ok ( KclValue :: Object {
917+ ( KclValue :: Sketch { value : sk } , Property :: String ( prop) , false ) if prop == "tags" => Ok ( KclValue :: Object {
913918 meta : vec ! [ Metadata {
914919 source_range: SourceRange :: from( self . clone( ) ) ,
915920 } ] ,
@@ -919,7 +924,7 @@ impl Node<MemberExpression> {
919924 . map ( |( k, tag) | ( k. to_owned ( ) , KclValue :: TagIdentifier ( Box :: new ( tag. to_owned ( ) ) ) ) )
920925 . collect ( ) ,
921926 } ) ,
922- ( being_indexed, _) => {
927+ ( being_indexed, _, _ ) => {
923928 let t = being_indexed. human_friendly_type ( ) ;
924929 let article = article_for ( t) ;
925930 Err ( KclError :: Semantic ( KclErrorDetails {
@@ -1919,10 +1924,11 @@ impl Property {
19191924 LiteralIdentifier :: Identifier ( identifier) => {
19201925 let name = & identifier. name ;
19211926 if !computed {
1922- // Treat the property as a literal
1927+ // This is dot syntax. Treat the property as a literal.
19231928 Ok ( Property :: String ( name. to_string ( ) ) )
19241929 } else {
1925- // Actually evaluate memory to compute the property.
1930+ // This is bracket syntax. Actually evaluate memory to
1931+ // compute the property.
19261932 let prop = exec_state. stack ( ) . get ( name, property_src) ?;
19271933 jvalue_to_prop ( prop, property_sr, name)
19281934 }
@@ -1940,10 +1946,9 @@ impl Property {
19401946 } ) )
19411947 }
19421948 }
1943- LiteralValue :: String ( s) => Ok ( Property :: String ( s) ) ,
19441949 _ => Err ( KclError :: Semantic ( KclErrorDetails {
19451950 source_ranges : vec ! [ sr] ,
1946- message : "Only strings or numbers (>= 0) can be properties/ indexes" . to_owned ( ) ,
1951+ message : "Only numbers (>= 0) can be indexes" . to_owned ( ) ,
19471952 } ) ) ,
19481953 }
19491954 }
0 commit comments