Skip to content

Scope definitions should not depend on JSON member order #401

Open

Description

@djolertrk

The scope schema says definitions are evaluated in order, allowing later variables to reference earlier ones. But JSON objects are unordered.

For example:

{
  "define": {
    "start": 0,
    "end": {"~sum": ["start", 32]}
  },
  "in": {
    "location": "memory",
    "offset": "start",
    "length": "end"
  }
}

Sorting the keys puts end before start, breaking the dependency under the current wording.

In solc, we work around this by emitting a separate nested define/in scope for each binding.

Could the spec use an explicitly ordered representation, or define evaluation without relying on object member order?

Raised during solc review.

Activity

  1. gnidan commented on Nov 10, 2026

    @gnidan
    Member

    Thanks for raising this! We can't rely on member order, but how about this: #408 makes order irrelevant by allowing members of a define to reference each other (or reference identifiers defined outside the block). Cycles are explicitly prohibited. This is already how pointers work for things like .length referencing .offset, so I think it makes sense to extend this to members within a define block. Let me know if this suffices please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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