From a8fc547f786f17ad5a2176d9041a8d1f76895748 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 8 Jan 2016 11:36:36 -0500 Subject: [PATCH] cmd/compile: apply -importmap to imports before checking for package unsafe There are fewer special cases this way: the import map applies to all import paths, not just the ones not spelled "unsafe". This is also consistent with what the code in cmd/go and go/build expects. They make no exception for "unsafe". For #13703. Change-Id: I622295261ca35a6c1e83e8508d363bddbddb6c0a Reviewed-on: https://go-review.googlesource.com/18438 Reviewed-by: Ian Lance Taylor Run-TryBot: Russ Cox Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/lex.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index 830c56df60..fb30d58527 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -694,7 +694,13 @@ func importfile(f *Val, line int) { errorexit() } - if f.U.(string) == "unsafe" { + path_ := f.U.(string) + + if mapped, ok := importMap[path_]; ok { + path_ = mapped + } + + if path_ == "unsafe" { if safemode != 0 { Yyerror("cannot import package unsafe") errorexit() @@ -706,12 +712,6 @@ func importfile(f *Val, line int) { return } - path_ := f.U.(string) - - if mapped, ok := importMap[path_]; ok { - path_ = mapped - } - if islocalname(path_) { if path_[0] == '/' { Yyerror("import path cannot be absolute path") -- 2.50.0