Skip to content

Commit

Permalink
fix: goexports to convert value type only for untyped constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Sep 27, 2019
1 parent 0f46cd5 commit 2c2b471
Show file tree
Hide file tree
Showing 24 changed files with 4,260 additions and 45 deletions.
13 changes: 13 additions & 0 deletions _test/time9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"time"
)

func main() {
fmt.Println((5 * time.Minute).Seconds())
}

// Output:
// 300
7 changes: 6 additions & 1 deletion cmd/goexports/goexports.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ func genContent(dest, pkgName, license string) ([]byte, error) {
pname := path.Base(pkgName) + "." + name
switch o := o.(type) {
case *types.Const:
val[name] = Val{fixConst(pname, o.Val()), false}
if b, ok := o.Type().(*types.Basic); ok && (b.Info()&types.IsUntyped) != 0 {
// convert untyped constant to right type to avoid overflow
val[name] = Val{fixConst(pname, o.Val()), false}
} else {
val[name] = Val{pname, false}
}
case *types.Func:
val[name] = Val{pname, false}
case *types.Var:
Expand Down
8 changes: 4 additions & 4 deletions stdlib/go1_11_debug_elf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions stdlib/go1_11_debug_macho.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_11_os.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_11_time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions stdlib/go1_12_debug_elf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions stdlib/go1_12_debug_macho.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_12_os.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_12_time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions stdlib/go1_13_debug_elf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions stdlib/go1_13_debug_macho.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_13_os.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stdlib/go1_13_time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stdlib/syscall/go1_11_syscall_windows_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stdlib/syscall/go1_11_syscall_windows_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c2b471

Please sign in to comment.