Skip to content

fromSb3: Auto-coercing "number/text" procedure inputs into numbers loses data #112

@towerofnix

Description

@towerofnix

I haven't tested but it seems that a procedure input which gets passed onto random might, for example, lose the decimal suffix in 123.0 with obvious semantic value — as well as more subtle string-vs-number cases in Scratch.

As complete compatibility with Scratch hadn't been a major concern, this wasn't a major issue, but now that we're narrowing in and recently did a lot of work on type-casting compatibility, we should ensure this is compatible.

It's OK to always serialize the input as a string, which is a quick fix, but we can do better with static analysis: if the argument is only ever passed to block inputs which take numbers and not any other types, it's safe to coerce the input into a number. (See #93, foundational to this kind of analysis.)

This is possibly a separate issue, but we may want to reinspect how the type of procedure arguments is interpreted: if a procedure input is only ever provided with number-returning blocks (or coerced numbers), we can treat the return type of the argument block as number, but otherwise we have to convert it from string (when non-strings are desired).

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedThis is blocked on other changes or resolutionscompatibilityMismatch or currently unsupported language behaviorfmt: SB3Pertains to SB3 format (Scratch 3.0)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions