google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.3k stars 209 forks source link

Immutability of Int is broken by BigInt() method #332

Closed cloudgerman closed 3 years ago

cloudgerman commented 3 years ago

Hi, First of all, great work! It is a pleasure working the library. I realized that Int's interface is immutable, except for the following method (big.Int is mutable):

// BigInt returns the value as a big.Int. // The returned variable must not be modified by the client. func (i Int) BigInt() *big.Int { ... }

Is that for a reason? I see the method is used internally in several places. I would imagine it is better to split it in 2:

If this is something that would be approved, I can work on the change and send a pull request.

Best, Germán

alandonovan commented 3 years ago

Fair enough, let's make BigInt return a copy, and bigInt avoid the copy if possible. Thanks.