Commit 8bd222f0 authored by Robert Griesemer's avatar Robert Griesemer

go/types: handle import "C" more like cmd/compile

Fixes #12667.

Change-Id: I68e73e26da9938606304163ae2637e3c6bacd6f6
Reviewed-on: https://go-review.googlesource.com/14722Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
parent 3d91624f
......@@ -55,6 +55,7 @@ var tests = [][]string{
{"testdata/errors.src"},
{"testdata/importdecl0a.src", "testdata/importdecl0b.src"},
{"testdata/importdecl1a.src", "testdata/importdecl1b.src"},
{"testdata/importC.src"}, // special handling in checkFiles
{"testdata/cycles.src"},
{"testdata/cycles1.src"},
{"testdata/cycles2.src"},
......@@ -245,6 +246,10 @@ func checkFiles(t *testing.T, testfiles []string) {
// typecheck and collect typechecker errors
var conf Config
// special case for importC.src
if len(testfiles) == 1 && testfiles[0] == "testdata/importC.src" {
conf.FakeImportC = true
}
conf.Importer = importer.Default()
conf.Error = func(err error) {
if *listErrors {
......
......@@ -202,6 +202,11 @@ func (check *Checker) collectObjects() {
name := imp.name
if s.Name != nil {
name = s.Name.Name
if path == "C" {
// match cmd/compile (not prescribed by spec)
check.errorf(s.Name.Pos(), `cannot rename import "C"`)
continue
}
if name == "init" {
check.errorf(s.Name.Pos(), "cannot declare init - must be func")
continue
......@@ -216,6 +221,11 @@ func (check *Checker) collectObjects() {
check.recordImplicit(s, obj)
}
if path == "C" {
// match cmd/compile (not prescribed by spec)
obj.used = true
}
// add import to file scope
if name == "." {
// merge imported scope with file scope
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package importC
import "C"
import _ /* ERROR cannot rename import "C" */ "C"
import foo /* ERROR cannot rename import "C" */ "C"
import . /* ERROR cannot rename import "C" */ "C"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment