Skip to content

Commit

Permalink
Convert to string using rune() again
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Jan 31, 2022
1 parent b270184 commit 3f0c7f8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion base/untyped/lit.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ again:

i, exact := constant.Int64Val(val)
if exact {
ret = string(i)
ret = string(rune(i))
} else {
ret = "\uFFFD"
}
Expand Down

1 comment on commit 3f0c7f8

@cosmos72
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion untyped integer -> untyped string is supported for any integer value - see https://go.dev/ref/spec#Conversions

So your proposal to narrow int64 -> rune would remove the top 32 bits, and produce a valid rune for numbers like 0x100000021.
Instead such large numbers are (and should be) automatically converted to "\uFFFD" by the conversion string(i)

Please sign in to comment.