Skip to content

Incorrect checking for use of argument defaults #5431

@B1j2754

Description

@B1j2754

Expected Behavior

Argument defaults clearly set in the Scratch json:
Image

Argument defaults in procedures should be used when a nullish input is received. For string (%s) and number (%n) inputs, a blank input ("") should be detected, and the default value should be used.

This means that a procedure call, empty values, as well as arguments not existing, should trigger the use of argument defaults.

Actual Behavior

In reality, the VM uses if (Object.prototype.hasOwnProperty.call(args, paramIds[i])) { in scratch3_procedures.js, which means that it checks for the argument's existence instead. This means that even when inputs are blank (nullish), the program just uses a blank argument.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to 'https://scratch.mit.edu/projects/1193044263/'
  2. Click on 'See Inside'
  3. Click the procedure call with empty parameters greet () () <> and notice its lack of use of argument defaults, despite empty parameters
  4. Click on the procedure call with parameters greet (george) (hello) <(1)=(1)> and notice its use of regular arguments
  5. Click on the procedure call with parameters example number ( ) and notice how it DOES use the argument default. This is because I have removed its input in the json, effectively making it undefined

System Details

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Screenshots

Code to reproduce bug:
Image

Argument defaults clearly set in the Scratch json:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions