masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
139 stars 15 forks source link

Spectacular failure when taking a substring that's out of range #525

Closed masak closed 5 years ago

masak commented 5 years ago

This is quite a spectacular error message:

$ bin/007 -e='say("foo".substr(4, 2))'
Earlier failure:
 (HANDLED) Start argument to substr out of range. Is: 4, should be in 0..3; use *-4 if you want to index relative to the end
  in sub substr at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 409
  in method call at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 231
  in method eval at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 628
  in method eval at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 1
  in method run at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 849
  in method run at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 1062
  in method run at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 37
  in block  at bin/007 line 16
  in sub run_007 at bin/007 line 47
  in sub MAIN at bin/007 line 66
  in block <unit> at bin/007 line 23

Final error:
 Type check failed in assignment to $!value; expected Str but got Failure (&CORE::infix:<orelse>...)
  in sub substr at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 409
  in method call at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 231
  in method eval at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 628
  in method eval at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 1
  in method run at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 849
  in method run at /home/masak/ours/007/lib/_007/Q.pm6 (_007::Q) line 1062
  in method run at /home/masak/ours/007/lib/_007/Runtime.pm6 (_007::Runtime) line 37
  in block  at bin/007 line 16
  in sub run_007 at bin/007 line 47
  in sub MAIN at bin/007 line 66
  in block <unit> at bin/007 line 23

I believe we might be missing a test for this case. Needless to say, there should be a 007-generated error here, not... whatever it is that happens above.