Skip to content

[BUG] Additions to the OperatorTable don't appear to be registering correctly #494

@cbrazinski

Description

@cbrazinski

Description

When registering a new assignment operator with the OperatorTable, attempts to use the new operator result in an Exception: Sequence does not respond to <newly added operator>. Interestingly, the operator does seem to function for objects formatted as a string and run with doString(). The operator will also work correctly when registered the exact same way via the Io Repl. Various Stack Overflow questions seem to concern others noticing this behavior. This question has one answer implying this behavior is actually correct/expected, but is followed by an answer from the original poster claiming that they saw different behavior upon running a different version of Io. The response to this question once again implies that this behavior is known and expected and explains this is the result of trying to limit parsing of source files to a single pass. The answer also mentions using doFile() as a work around.

Is this a bug or intended behavior? If this is working as intended, I'll mention I found it unintuitive and surprising, especially given that other similar features aren't subject to this limitation (e.g. assigning custom curly brace behavior).

Steps to Reproduce

OperatorTable addAssignOperator(":", "atPutNumber")
curlyBrackets := method(
	r := Map clone
	call message arguments foreach(arg,
		r doMessage(arg)
	)
	r
)

Map atPutNumber := method(
	self atPut(
		call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""),
		call evalArgAt(1)
	)
)

workingMap := doString("{ \"Bob\" : \"1234\", \"Mary\" : \"5678\" }")
workingMap type println
workingMap keys println
workingMap foreach(k,v, writeln(k, " : ", v))

triggersException := { "Bob" : "1234", "Mary" : "5678" }
triggersException type println
triggersException keys println
triggersException foreach(k,v, writeln(k, " : ", v))

Expected Behavior

I would expect both workingMap and triggersException in the above example to both evaluate the new operator ( ':' ) in the same manner, in this case resulting in identical Maps, each containing two elements:

$ io map_literal.io 
Map
list(Bob, Mary)
Bob : 1234
Mary : 5678

Map
list(Bob, Mary)
Bob : 1234
Mary : 5678

Actual Behavior

Instead, while workingMap evaluates as expected, triggersException results in a Sequence does not respond to ':' Exception.

$ io map_literal.io 
Map
list(Mary, Bob)
Mary : 5678
Bob : 1234

  Exception: Sequence does not respond to ':'
  ---------
  nothing on stack

Environment

  • Io Version: Io Programming Language, v. 20260302
  • Operating System: Ubuntu 24.04.4 LTS
  • Architecture: x86_64 (AMD)
  • Build Type: from source

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as intendedcriticalCrashes, data loss, or fundamentally broken behaviorparserLexer, parser, operator shuffling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions