Add a warning for is to anticipate using it as a keyword (#5229)

Co-authored-by: Malo <57839069+MDLC01@users.noreply.github.com>
This commit is contained in:
Ian Wrzesinski 2024-10-31 07:55:31 -04:00 committed by GitHub
parent b969c01b28
commit dcb130bd71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
use comemo::Tracked; use comemo::Tracked;
use typst_library::diag::warning;
use typst_library::engine::Engine; use typst_library::engine::Engine;
use typst_library::foundations::{Context, IntoValue, Scopes, Value}; use typst_library::foundations::{Context, IntoValue, Scopes, Value};
use typst_library::World; use typst_library::World;
@ -47,6 +48,16 @@ impl<'a> Vm<'a> {
if self.inspected == Some(var.span()) { if self.inspected == Some(var.span()) {
self.trace(value.clone()); self.trace(value.clone());
} }
// This will become an error in the parser if 'is' becomes a keyword.
if var.get() == "is" {
self.engine.sink.warn(warning!(
var.span(),
"`is` will likely become a keyword in future versions and will \
not be allowed as an identifier";
hint: "rename this variable to avoid future errors";
hint: "try `is_` instead"
));
}
self.scopes.top.define_ident(var, value); self.scopes.top.define_ident(var, value);
} }