Skip to content

Return an "ambiguous import" error in case of an ambiguos imports #1024

@zapateo

Description

@zapateo

Currently, when compiling a program with Scriggo, if a path is imported that is provided both as a Go source file and as a native package, the Scriggo build takes the Go source file into account, ignoring the native package entirely.

This behavior can be ambiguous and create unexpected situations.

One option is to return an "ambiguous import" error in these scenarios, thus clearly indicating that you are attempting to do something ambiguous.

What the Go compiler does

For a useful reference, this is the behavior of the Go compiler. Consider this scenario:

.
├── exec
│   └── a.go
├── go.mod
└── main.go

where main.go contains:

package main

import "os/exec" // <- the ambiguous import

func main() {
	_ = exec.A
}

the go.mod contains:

module os

go 1.26.1

and exec/a.go contains:

package exec

var A = 10

If the package is compiled with:

go build

this error is returned:

ambiguous import: found package os in multiple modules:
        os (/home/user/...)
         (/home/user/.../go1.26.1.linux-amd64/go/src/os)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions