scriggo icon indicating copy to clipboard operation
scriggo copied to clipboard

compiler/checker: investigate if importing the same name twice is handled correctly

Open zapateo opened this issue 3 years ago • 3 comments

In the function checkImport we import the names without checking if they have already been imported. Not sure if this may lead to incosistencies, we should investigate on it.

NOTE: before proceeding, wait for the merge of the PR #856.

zapateo avatar Sep 10 '21 14:09 zapateo

Consider this scenario:

// main.go
package main

import (
	. "test/bar"
	. "test/foo"
)

func main() {
	Foo()
	Bar()
}

// bar/bar.go
package bar

func F() {}

func Bar() {}

// foo/foo.go
package foo

func F() {}

func Foo() {}

gc returns the error:

./main.go:5:2: F redeclared during import "test/foo"
        main.go:4:2: previous declaration during import "test/bar"

zapateo avatar Sep 15 '21 15:09 zapateo

We should consider and test the various combinations of native and non-native imported names. For example:

  • first declaration imported is native, a second one (with the same name) is native too
  • first declaration imported is native, a second one (with the same name) is not native

etc...

zapateo avatar Sep 23 '21 14:09 zapateo

This code does not return error:

"https://github.com/open2b/scriggo/issues/859": {
	sources: fstest.Files{
		"index.html": `
		{% import "foo.html" %}
		{% import "bar.html" %}

		{{ Foo() }}
		{{ Bar() }}
	`,
		"foo.html": `
		{% macro F() %}{% end macro %}
		{% macro Foo() %}{% end macro %}
	`,
		"bar.html": `
		{% macro F() %}{% end macro %}
		{% macro Bar() %}{% end macro %}
	`,
	},
},

Neither this:

"https://github.com/open2b/scriggo/issues/859": {
	sources: fstest.Files{
		"index.html": `
			{% import "foo.html" %}
			{% import "bar.html" %}`,
		"foo.html": `{% macro F() %}{% end macro %}`,
		"bar.html": `{% macro F() %}{% end macro %}`,
	},
},

They both should return a redeclaration error.

zapateo avatar Sep 23 '21 14:09 zapateo