MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / representation

Method representation

types/expr.go:465–486  ·  view source on GitHub ↗

representation returns the representation of the constant operand x as the basic type typ. If no such representation is possible, it returns a non-zero error code.

(x *operand, typ *Basic)

Source from the content-addressed store, hash-verified

463//
464// If no such representation is possible, it returns a non-zero error code.
465func (check *Checker) representation(x *operand, typ *Basic) (constant.Value, errorCode) {
466 assert(x.mode == constant_)
467 v := x.val
468 if !representableConst(x.val, check, typ, &v) {
469 if isNumeric(x.typ) && isNumeric(typ) {
470 // numeric conversion : error msg
471 //
472 // integer -> integer : overflows
473 // integer -> float : overflows (actually not possible)
474 // float -> integer : truncated
475 // float -> float : overflows
476 //
477 if !isInteger(x.typ) && isInteger(typ) {
478 return nil, _TruncatedFloat
479 } else {
480 return nil, _NumericOverflow
481 }
482 }
483 return nil, _InvalidConstVal
484 }
485 return v, 0
486}
487
488func (check *Checker) invalidConversion(code errorCode, x *operand, target Type) {
489 msg := "cannot convert %s to %s"

Callers 2

representableMethod · 0.95
implicitTypeAndValueMethod · 0.95

Calls 4

representableConstFunction · 0.85
isNumericFunction · 0.85
isIntegerFunction · 0.85
assertFunction · 0.70

Tested by

no test coverage detected