Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in Chrono.duration.toText #955

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

quag
Copy link
Contributor

@quag quag commented Feb 25, 2024

There are three mistakes in Chrono.duration.toText:

  1. incorrect argument order for text.getRange
  2. incorrect argument order for text.firstIndexOf
  3. assuming text.firstIndexOf returns in int rather than FoundAt index or NotFound

These three bugs caused packages/Examples/clock.candy to panic.

2024-02-25T22:32:38.353578Z DEBUG candy::run: Running Examples:clock.
2024-02-25T22:32:39.753290Z DEBUG candy::run: Compilation took 1399 ms.
2024-02-25T22:32:39.753301Z DEBUG candy::run: Running program.
2024-02-25T22:32:39.762745Z ERROR candy::run: The program panicked: `endExclusive | typeIs Int` was not satisfied
2024-02-25T22:32:39.762747Z ERROR candy::run: Chrono:duration:toText:121 is responsible.
2024-02-25T22:32:39.762889Z ERROR candy::run: This is the stack trace:
packages/Builtins/_.candy:570:3 – 570:36            needs False "`endExclusive | typeIs Int` was not satisfied" Chrono:duration:toText:121
packages/Chrono/duration.candy:198:7 – 198:55       {…} "0." 0 (FoundAt 1)
packages/Examples/clock.candy:9:23 – 9:73           {…} (Duration (FixedDecimal [MinorUnits: 1708900359, Scale: 0]))
tooling:user::                                      {…} [Arguments: (,), FileSystem: [File: [Close: { … }, Open: { … }, ReadToEnd: { … }]], GetRandomBytes: { … }, HttpServer: { … }, Stdin: { … }, Stdout: { … }, SystemClock: { … }]
2024-02-25T22:32:39.762892Z DEBUG candy::run: Execution took 9 ms.

Checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

There are three mistakes in Chrono.duration.toText:
1. incorrect argument order for text.getRange
2. incorrect argument order for text.firstIndexOf
3. assuming text.firstIndexOf returns in int rather than FoundAt index or
   NotFound

These three bugs caused packages/Examples/clock.candy to panic.

```
2024-02-25T22:32:38.353578Z DEBUG candy::run: Running Examples:clock.
2024-02-25T22:32:39.753290Z DEBUG candy::run: Compilation took 1399 ms.
2024-02-25T22:32:39.753301Z DEBUG candy::run: Running program.
2024-02-25T22:32:39.762745Z ERROR candy::run: The program panicked: `endExclusive | typeIs Int` was not satisfied
2024-02-25T22:32:39.762747Z ERROR candy::run: Chrono:duration:toText:121 is responsible.
2024-02-25T22:32:39.762889Z ERROR candy::run: This is the stack trace:
packages/Builtins/_.candy:570:3 – 570:36            needs False "`endExclusive | typeIs Int` was not satisfied" Chrono:duration:toText:121
packages/Chrono/duration.candy:198:7 – 198:55       {…} "0." 0 (FoundAt 1)
packages/Examples/clock.candy:9:23 – 9:73           {…} (Duration (FixedDecimal [MinorUnits: 1708900359, Scale: 0]))
tooling:user::                                      {…} [Arguments: (,), FileSystem: [File: [Close: { … }, Open: { … }, ReadToEnd: { … }]], GetRandomBytes: { … }, HttpServer: { … }, Stdin: { … }, Stdout: { … }, SystemClock: { … }]
2024-02-25T22:32:39.762892Z DEBUG candy::run: Execution took 9 ms.
```
@jwbot jwbot enabled auto-merge February 25, 2024 22:49
@JonasWanke JonasWanke self-requested a review February 26, 2024 06:59
Copy link
Member

@JonasWanke JonasWanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

BTW, the argument orders were correct, they were just using the pipe operator (|) which we haven't documented yet (filed #959): firstArgument | function remainingArguments is mostly equivalent to function firstArgument remainingArguments

@JonasWanke JonasWanke disabled auto-merge February 26, 2024 07:10
@JonasWanke JonasWanke merged commit e54c5be into candy-lang:main Feb 26, 2024
7 of 9 checks passed
@quag
Copy link
Contributor Author

quag commented Feb 26, 2024

Fascinating. I never would have guessed that about the argument order. In what situations is (a | f b c) not the same as (f a b c)?

@JonasWanke
Copy link
Member

a | f b c evaluates the subexpressions in the order a, f, b, c, whereas f a b c evaluates them in the order f, a, b, c, so both in reading order. But this only makes a difference if they are both impure, e.g., because they panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants