(e ast.Expr)
| 185 | } |
| 186 | |
| 187 | func (c *checker) checkOptSelect(e ast.Expr) { |
| 188 | // Collect metadata related to the opt select call packaged by the parser. |
| 189 | call := e.AsCall() |
| 190 | if len(call.Args()) != 2 || call.IsMemberFunction() { |
| 191 | t := "" |
| 192 | if call.IsMemberFunction() { |
| 193 | t = " member call with" |
| 194 | } |
| 195 | c.errors.notAnOptionalFieldSelectionCall(e.ID(), c.location(e), |
| 196 | fmt.Sprintf( |
| 197 | "incorrect signature.%s argument count: %d", t, len(call.Args()))) |
| 198 | return |
| 199 | } |
| 200 | |
| 201 | operand := call.Args()[0] |
| 202 | field := call.Args()[1] |
| 203 | fieldName, isString := maybeUnwrapString(field) |
| 204 | if !isString { |
| 205 | c.errors.notAnOptionalFieldSelection(field.ID(), c.location(field), field) |
| 206 | return |
| 207 | } |
| 208 | |
| 209 | // Perform type-checking using the field selection logic. |
| 210 | resultType := c.checkSelectField(e, operand, fieldName, true) |
| 211 | c.setType(e, substitute(c.mappings, resultType, false)) |
| 212 | c.setReference(e, ast.NewFunctionReference("select_optional_field")) |
| 213 | } |
| 214 | |
| 215 | func (c *checker) checkSelectField(e, operand ast.Expr, field string, optional bool) *types.Type { |
| 216 | // Interpret as field selection, first traversing down the operand. |
no test coverage detected