fix: slice bug

This commit is contained in:
Shunsuke Shibayama 2024-12-27 20:21:05 +09:00
parent deb6736f9f
commit 0da66dceca
2 changed files with 13 additions and 0 deletions

View File

@ -1886,6 +1886,7 @@ impl ASTConverter {
);
method.call1(self.convert_expr(*subs.slice))
}
// [:] == [slice(None)]
// [start:] == [slice(start, None)]
// [:stop] == [slice(stop)]
// [start:stop] == [slice(start, stop)]
@ -1905,6 +1906,14 @@ impl ASTConverter {
if let Some(step) = step {
args.push_pos(PosArg::new(step));
}
if args.is_empty() {
args.push_pos(PosArg::new(Expr::Literal(Literal::new(Token::new(
TokenKind::NoneLit,
"None",
loc.row.get(),
loc.column.to_zero_indexed(),
)))));
}
let slice = self.convert_ident("slice".to_string(), loc);
slice.call(args).into()
}

View File

@ -1,5 +1,9 @@
l = [1, 2, 3]
_ = l[1:2]
_ = l[:]
_ = l[1:]
_ = l[:1]
_ = l[1:1:1]
print(l[2])
print(l["a"]) # ERR