Skip to content

Commit

Permalink
ast: future.compat import (#6285)
Browse files Browse the repository at this point in the history
Adding `future.compat` import for enforcing strict-mode checks and additional `1.0` behavior for the module.

Fixes: #6247
Signed-off-by: Johan Fylling <[email protected]>
  • Loading branch information
johanfylling authored Oct 20, 2023
1 parent a0ed11b commit c76d5d6
Show file tree
Hide file tree
Showing 11 changed files with 866 additions and 27 deletions.
15 changes: 8 additions & 7 deletions ast/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,8 @@ func (c *Compiler) checkUnsafeBuiltins() {

func (c *Compiler) checkDeprecatedBuiltins() {
for _, name := range c.sorted {
errs := checkDeprecatedBuiltins(c.deprecatedBuiltinsMap, c.Modules[name], c.strict)
mod := c.Modules[name]
errs := checkDeprecatedBuiltins(c.deprecatedBuiltinsMap, mod, c.strict || mod.futureCompatible)
for _, err := range errs {
c.err(err)
}
Expand Down Expand Up @@ -1495,7 +1496,7 @@ func (c *Compiler) init() {

for _, bi := range c.capabilities.Builtins {
c.builtins[bi.Name] = bi
if c.strict && bi.IsDeprecated() {
if bi.IsDeprecated() {
c.deprecatedBuiltinsMap[bi.Name] = struct{}{}
}
}
Expand Down Expand Up @@ -1570,12 +1571,12 @@ func (c *Compiler) GetAnnotationSet() *AnnotationSet {
}

func (c *Compiler) checkDuplicateImports() {
if !c.strict {
return
}

for _, name := range c.sorted {
mod := c.Modules[name]
if !c.strict && !mod.futureCompatible {
continue
}

processedImports := map[Var]*Import{}

for _, imp := range mod.Imports {
Expand All @@ -1593,7 +1594,7 @@ func (c *Compiler) checkDuplicateImports() {
func (c *Compiler) checkKeywordOverrides() {
for _, name := range c.sorted {
mod := c.Modules[name]
errs := checkKeywordOverrides(mod, c.strict)
errs := checkKeywordOverrides(mod, c.strict || mod.futureCompatible)
for _, err := range errs {
c.err(err)
}
Expand Down
Loading

0 comments on commit c76d5d6

Please sign in to comment.