Skip to content

Commit 853e795

Browse files
committed
compiler: Restore previous behavior of skipping unsafe import.
If its code were to be generated, package unsafe ends up largely empty: $packages["unsafe"] = (function() { var $pkg = {}, $init; $init = function() { $pkg.$init = function() {}; ... }; $pkg.$init = $init; return $pkg; })(); It contains an empty (aside from goroutine/blocking bookkeeping code) init function, and that's the only thing that gets called by other packages. So, we don't want to start including it. This change restores the previous behavior (with Go 1.8) of skipping it. Helps gopherjs/gopherjs.github.io#67 (comment). Related to https://golang.org/cl/37694.
1 parent ac3a68a commit 853e795

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

compiler/package.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
217217
var importDecls []*Decl
218218
var importedPaths []string
219219
for _, importedPkg := range typesPkg.Imports() {
220+
if importedPkg == types.Unsafe {
221+
// Prior to Go 1.9, unsafe import was excluded by Imports() method,
222+
// but now we do it here to maintain previous behavior.
223+
continue
224+
}
220225
c.p.pkgVars[importedPkg.Path()] = c.newVariableWithLevel(importedPkg.Name(), true)
221226
importedPaths = append(importedPaths, importedPkg.Path())
222227
}

0 commit comments

Comments
 (0)