Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

for-loop over byte ranges gives type error on try.ceylon-lang.org #7450

@ePaul

Description

@ePaul

Wrong behavior
Try to iterate over a range of bytes with a for-loop:

for (b in 0.byte..3.byte) {
    print(b);
}

Try it!
Trying to run this on try.ceylon-lang.org gives this error:

	undefined	 — 	Runtime error:
	undefined	 — 	--- TypeError: $1i.compare is not a function
Script ended with no output

Expected behavior
Running this code should print

0
1
2
3

Analysis
From the error message, it looks like some part of the compiler is trying to convert this into a classic increment-comparison loop. But bytes in Ceylon have no total ordering, and thus also no comparison operators or compare functions.

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