Skip to content

Commit

Permalink
Strings are measured with 'length', Lists are measured with 'the numb…
Browse files Browse the repository at this point in the history
…er of elements'

See tc39/ecma262#3412 (comment)
  • Loading branch information
jmdyck committed Oct 22, 2024
1 parent b80d92e commit 7863b91
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pseudocode_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10038,6 +10038,10 @@ def s_tb(val_desc, env):
[led, ex] = val_desc.children
env.assert_expr_is_of_type(ex, T_MathInteger_)
(led_sub_t, led_sup_t) = type_bracket_for(led, env)
add_pass_error(
val_desc,
"Strings are measured with 'length', Lists are measured with 'the number of elements'"
)
return a_subset_of(ListType(led_sup_t))
# inexact because of length restriction

Expand Down Expand Up @@ -10346,6 +10350,10 @@ def s_cond(cond, env0, asserting):
[list_var, len_var] = cond.children
env0.assert_expr_is_of_type(list_var, T_List)
env0.assert_expr_is_of_type(len_var, T_MathNonNegativeInteger_)
add_pass_error(
list_var,
"Strings are measured with 'length', Lists are measured with 'the number of elements'"
)
return (env0, env0)

@P("{EXPR} : the number of elements in the List {var}")
Expand Down Expand Up @@ -11517,6 +11525,10 @@ def s_expr(expr, env0, _):
env0.assert_expr_is_of_type(var1, T_MathInteger_)
env1 = env0.ensure_expr_is_of_type(var3, T_Data_Block | T_Shared_Data_Block)
env0.assert_expr_is_of_type(var4, T_MathInteger_)
add_pass_error(
expr,
"Strings are measured with 'length', Lists are measured with 'the number of elements'"
)
return (ListType(T_MathInteger_), env1)

@P("{EXPR} : a List whose elements are bytes from {var} at indices in {INTERVAL}")
Expand Down Expand Up @@ -14418,6 +14430,10 @@ class _:
def s_expr(expr, env0, _):
[var] = expr.children
env0.assert_expr_is_of_type(var, T_MathInteger_)
add_pass_error(
expr,
"Strings are measured with 'length', Lists are measured with 'the number of elements'"
)
return (ListType(T_MathInteger_), env0)

@P("{LIST_ELEMENTS_DESCRIPTION} : byte values")
Expand Down

0 comments on commit 7863b91

Please sign in to comment.