Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/printer: rewrite import foo to import "foo" #9644

Closed
rsc opened this issue Jan 20, 2015 · 5 comments
Closed

go/printer: rewrite import foo to import "foo" #9644

rsc opened this issue Jan 20, 2015 · 5 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jan 20, 2015

It might be that go/printer should rewrite

import `foo`

to

import "foo"

so that all import statements use double-quoted strings. This is unlikely in practice, but I found myself making this assumption in a textual rewriter (and we've made this assumption in commands that update old code.google.com subrepo imports) and I was surprised that the backquoted form gets through gofmt.

http://play.golang.org/p/XS-iKGjQWe

We should think about this for Go 1.5.

@griesemer

@rsc rsc added this to the Go1.5 milestone Jan 20, 2015
@griesemer
Copy link
Contributor

The spec simply wants a string literal there, so both string forms are permitted.

It's fine to have gofmt produce only double-quoted strings.

@bradfitz
Copy link
Contributor

Maybe keep raw strings if the import has double quotes in it already. (which will be approximately 0% of programs in the wild)

@minux
Copy link
Member

minux commented Jan 21, 2015

According to http://golang.org/ref/spec#Import_declarations,
It's ok to reject " or ` in import paths, so I think we'd just reject
those paths and always use import "foo".

@griesemer
Copy link
Contributor

@minux The implementation restriction in http://golang.org/ref/spec#Import_declarations is already implemented (in gc I think, and in go/types for sure) and is applied to the runes of the string, but not the string's quotes. That is, both math and "math" are permitted.

It's trivial to do this in gofmt and there's no need to be overly restrictive in the compiler.

@minux
Copy link
Member

minux commented Jan 21, 2015

Right, so there is really no reason not to always rewrite import foo into
import "foo".

btw, my point about import path restrictions was replying to Brad's comment
about
import path containing double-quotes.

@griesemer griesemer self-assigned this Jan 22, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants