diff --git a/x/typesutil/check.go b/x/typesutil/check.go index dad82567d..03a3a5ef0 100644 --- a/x/typesutil/check.go +++ b/x/typesutil/check.go @@ -147,7 +147,7 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error) C2goBase: opts.C2goBase, LookupPub: c2go.LookupPub(mod), LookupClass: mod.LookupClass, - Importer: newImporter(conf.Importer, mod, nil, fset), + Importer: conf.Importer, Recorder: gopRecorder{p.gopInfo}, NoFileLine: true, NoAutoGenMain: true, diff --git a/x/typesutil/imp.go b/x/typesutil/imp.go deleted file mode 100644 index fa51c2472..000000000 --- a/x/typesutil/imp.go +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package typesutil - -import ( - "go/types" - "syscall" - - "github.com/goplus/gop" - "github.com/goplus/gop/token" - "github.com/goplus/gop/x/gopenv" - "github.com/goplus/mod/env" - "github.com/goplus/mod/gopmod" -) - -// ----------------------------------------------------------------------------- - -type nilImporter struct{} - -func (p nilImporter) Import(path string) (ret *types.Package, err error) { - return nil, syscall.ENOENT -} - -// ----------------------------------------------------------------------------- - -type importer struct { - imp types.Importer - alt *gop.Importer - - mod *gopmod.Module - gop *env.Gop - fset *token.FileSet -} - -func newImporter(imp types.Importer, mod *gopmod.Module, gop *env.Gop, fset *token.FileSet) types.Importer { - if imp == nil { - imp = nilImporter{} - } - if gop == nil { - gop = gopenv.Get() - } - return &importer{imp, nil, mod, gop, fset} -} - -func (p *importer) Import(path string) (ret *types.Package, err error) { - ret, err = p.imp.Import(path) - if err == nil { - return - } - if p.alt == nil { - p.alt = gop.NewImporter(p.mod, p.gop, p.fset) - } - return p.alt.Import(path) -} - -// ----------------------------------------------------------------------------- diff --git a/x/typesutil/imp_test.go b/x/typesutil/imp_test.go deleted file mode 100644 index 9751a4ed6..000000000 --- a/x/typesutil/imp_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package typesutil - -import ( - "go/token" - "testing" -) - -func TestNilImport(t *testing.T) { - _, err := (&nilImporter{}).Import("fmt") - if err == nil { - t.Fatal("no error") - } - imp := newImporter(nil, nil, nil, token.NewFileSet()) - if imp.(*importer).imp == nil { - t.Fatal("nilImporter") - } - if imp.(*importer).gop == nil { - t.Fatal("gopenv.Get") - } -}