this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: clean up some TODOs for old Go versions

Now that we require Go 1.20 or later, we can simplify some of our code.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Iede54cc9b67806a5c4de8cffc88903e838106186
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167670
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+11 -25
+2 -3
cue/ast/astutil/sanitize.go
··· 332 332 } 333 333 } 334 334 335 - // TODO(go1.13): const mask = 0xff_ffff_ffff_ffff 336 - const mask = 0xffffffffffffff // max bits; stay clear of int64 overflow 337 - const shift = 4 // rate of growth 335 + const mask = 0xff_ffff_ffff_ffff // max bits; stay clear of int64 overflow 336 + const shift = 4 // rate of growth 338 337 for n := int64(0x10); ; n = int64(mask&((n<<shift)-1)) + 1 { 339 338 num := z.rand.Intn(int(n)) 340 339 name := fmt.Sprintf("%s_%01X", base, num)
+2 -13
encoding/gocode/templates.go
··· 15 15 package gocode 16 16 17 17 import ( 18 - "strings" 19 18 "text/template" 20 19 ) 21 20 ··· 36 35 37 36 `)) 38 37 39 - // normalizeHex copes with differences between the Go string literal conventions 40 - // between go1.18 and go1.19. The byte 0x7f changed from \u007f to \x7f. 41 - // By normalizing here, we make the code generation independent of the Go 42 - // version that's used. 43 - func normalizeHex(s string) string { 44 - return strings.ReplaceAll(s, `\u007f`, `\x7f`) 45 - } 46 - 47 38 // Inputs: 48 39 // .prefix prefix to all generated variable names 49 40 // .cueName name of the top-level CUE value ··· 75 66 // .prefix prefix to all generated variable names 76 67 // .runtime the variable name of a user-supplied runtime, if any 77 68 // .data bytes obtained from Instance.MarshalBinary 78 - var loadCode = template.Must(template.New("load").Funcs(template.FuncMap{ 79 - "normalizeHex": normalizeHex, 80 - }).Parse(` 69 + var loadCode = template.Must(template.New("load").Parse(` 81 70 var {{.prefix}}Codec, {{.prefix}}Instance_, {{.prefix}}Value = func() (*gocodec.Codec, *cue.Instance, cue.Value) { 82 71 var r *cue.Runtime 83 72 r = {{if .runtime}}{{.runtime}}{{else}}&cue.Runtime{}{{end}} ··· 113 102 } 114 103 115 104 // Data size: {{len .data}} bytes. 116 - var {{.prefix}}InstanceData = []byte({{printf "%+q" .data | normalizeHex }}) 105 + var {{.prefix}}InstanceData = []byte({{printf "%+q" .data }}) 117 106 `))
+7 -9
pkg/time/time_test.go
··· 35 35 36 36 // TODO: allow leap seconds? This is allowed by the RFC 3339 spec. 37 37 // `"2019-06-30T23:59:60Z"`, // leap seconds 38 + 39 + // NOTE: Go 1.17 rejected the extra digits, 40 + // and Go 1.18 started accepting them while discarding them. 41 + // We want CUE to be consistent across Go versions, 42 + // so we should probably fork Go's time package to behave exactly the 43 + // way we want and in a consistent way across Go versions. 44 + `"2019-01-02T15:04:05.01234567890-08:00"`, 38 45 } 39 46 40 47 for _, tc := range validTimes { ··· 71 78 `"2019-13-15T23:00:00Z"`, // month out of range 72 79 `"2019-01-02T15:04:05Z+08:00"`, // double time zone 73 80 `"2019-01-02T15:04:05+08"`, // partial time zone 74 - 75 - // TODO: Go 1.17 rejected the extra digits, 76 - // and Go 1.18 started accepting them while discarding them. 77 - // We want CUE to be consistent across Go versions, 78 - // so we should probably fork Go's time package to behave exactly the 79 - // way we want and in a consistent way across Go versions. 80 - // In the meantime, having newer Go versions accept more inputs is not a 81 - // terrible state of affairs, so for now we disable the test case. 82 - // `"2019-01-02T15:04:05.01234567890-08:00"`, 83 81 } 84 82 85 83 for _, tc := range invalidTimes {