Skip to content

Commit 6280b9e

Browse files
committed
pkg/strconv: remove ParseComplex
The CUE input import "strconv" complex: strconv.ParseComplex("+3i", 64) fails on master as well as v0.10.0 and older versions like v0.8.2: complex: unsupported Go type (complex128) This is because strconv.ParseComplex returns a complex128 Go value, and the internal/core/convert logic used to translate from Go values to CUE values does not handle complex128, given that CUE does not have direct support for complex numbers in the language spec. One option would be to rewrite strconv.ParseComplex to return a string, as a form of validator which would canonicalize complex number strings. This is how CUE's time.Parse API works; it returns a string given that the CUE language does not have direct support for timestamps. However, given that strconv.ParseComplex never worked, and it's not clear that it is needed, particularly as noone complained, remove it for the time being. Remove the switch case in pkg/gen.go too. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I96e327a61bbc5e9a620214540f7402131aa3f793 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201115 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 7a26789 commit 6280b9e

File tree

3 files changed

+0
-39
lines changed

3 files changed

+0
-39
lines changed

pkg/gen.go

-2
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ func (g *generator) adtKind(typ types.Type) string {
433433
return "adt.IntKind"
434434
case "Float64", "BigFloat", "Decimal":
435435
return "adt.NumberKind"
436-
case "Complex128":
437-
return "adt.TopKind" // TODO(mvdan): what should we return here?
438436
case "DecimalList", "StringList", "CueList":
439437
return "adt.ListKind"
440438
case "Bytes", "Reader":

pkg/strconv/pkg.go

-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/strconv/strconv.go

-24
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,6 @@ func FormatBool(b bool) string {
3737
return strconv.FormatBool(b)
3838
}
3939

40-
// ParseComplex converts the string s to a complex number
41-
// with the precision specified by bitSize: 64 for complex64, or 128 for complex128.
42-
// When bitSize=64, the result still has type complex128, but it will be
43-
// convertible to complex64 without changing its value.
44-
//
45-
// The number represented by s must be of the form N, Ni, or N±Ni, where N stands
46-
// for a floating-point number as recognized by ParseFloat, and i is the imaginary
47-
// component. If the second N is unsigned, a + sign is required between the two components
48-
// as indicated by the ±. If the second N is NaN, only a + sign is accepted.
49-
// The form may be parenthesized and cannot contain any spaces.
50-
// The resulting complex number consists of the two components converted by ParseFloat.
51-
//
52-
// The errors that ParseComplex returns have concrete type *NumError
53-
// and include err.Num = s.
54-
//
55-
// If s is not syntactically well-formed, ParseComplex returns err.Err = ErrSyntax.
56-
//
57-
// If s is syntactically well-formed but either component is more than 1/2 ULP
58-
// away from the largest floating point number of the given component's size,
59-
// ParseComplex returns err.Err = ErrRange and c = ±Inf for the respective component.
60-
func ParseComplex(s string, bitSize int) (complex128, error) {
61-
return strconv.ParseComplex(s, bitSize)
62-
}
63-
6440
// ParseFloat converts the string s to a floating-point number
6541
// with the precision specified by bitSize: 32 for float32, or 64 for float64.
6642
// When bitSize=32, the result still has type float64, but it will be

0 commit comments

Comments
 (0)