Explorer

core.type-call-type-arguments

description
The type arguments of a call: for each parameter of type `type`, check the argument against `type` and convert it to core.type-ast. An argument that is not entered (hole) is inferred with core.type-infer-type-argument
type
Fn(
  parameters: List<Record{name: String, type: @core.type-ast}>,
  arguments: List<Record{name: String, value: @core.expression}>,
  env: @core.type-env,
  index: Number,
  accum: List<Record{name: String, type: @core.type-ast}>,
  return_type: @core.type-ast,
  expected_type: Union{#none, #some(@core.type-ast)}
) -> Union{#ok(List<Record{name: String, type: @core.type-ast}>), #error(@core.type-error)}
expression
fn(parameters$0, arguments$1, env$2, index$3, accum$4, return_type$50, expected_type$51) =>
  match @core.list-get(list: $0, index: $3) {
    #none(_) =>
      #ok($4),
    #some(parameter$5) =>
      match @core.type-equals(t1: $5.type, t2: #type) {
        true =>
          match @core.call-argument-find(arguments: $1, name: $5.name, index: 0) {
            #none(_) =>
              @core.type-call-type-arguments(
                parameters: $0,
                arguments: $1,
                env: $2,
                index: @core.plus(left: $3, right: 1),
                accum: $4,
                return_type: $50,
                expected_type: $51
              ),
            #some(value$6) =>
              match $6 {
                #hole(type_argument_hole$52) =>
                  match $52.probe {
                    false =>
                      match @core.type-infer-type-argument(
                          name: $5.name,
                          parameters: $0,
                          arguments: $1,
                          env: $2,
                          index: 0,
                          return_type: $50,
                          expected_type: $51,
                          known: $4
                        ) {
                        #some(inferred_type$53) =>
                          @core.type-call-type-arguments(
                            parameters: $0,
                            arguments: $1,
                            env: $2,
                            index: @core.plus(left: $3, right: 1),
                            accum: @core.list-append(list: $4, item: {name: $5.name, type: $53}),
                            return_type: $50,
                            expected_type: $51
                          ),
                        _ =>
                          #error(#invalid_type_declaration({
                            message: @core.string-concat(
                              left: "the type argument '",
                              right: @core.string-concat(
                                left: $5.name,
                                right: "' is not entered and could not be inferred from the other arguments or the expected type"
                              )
                            )
                          }))
                      },
                    true =>
                      #error(#hole_expected_type({
                        expected: #some(#type),
                        inferred_type_argument: @core.type-infer-type-argument(
                          name: $5.name,
                          parameters: $0,
                          arguments: $1,
                          env: $2,
                          index: 0,
                          return_type: $50,
                          expected_type: $51,
                          known: $4
                        )
                      }))
                  },
                _ =>
                  match @core.type-check-against(expr: $6, env: $2, expected_type: #type) {
                    #error(error$7) =>
                      #error($7),
                    _ =>
                      match @core.type-expression-to-type-ast(expr: $6, parameters: $2.type_parameters) {
                        #none(_) =>
                          #error(#invalid_type_declaration({
                            message: "a type argument must be a type expression (a type, a type part, a call of a part that returns a type, or a type parameter)"
                          })),
                        #some(type$8) =>
                          @core.type-call-type-arguments(
                            parameters: $0,
                            arguments: $1,
                            env: $2,
                            index: @core.plus(left: $3, right: 1),
                            accum: @core.list-append(list: $4, item: {name: $5.name, type: $8}),
                            return_type: $50,
                            expected_type: $51
                          )
                      }
                  }
              }
          },
        false =>
          @core.type-call-type-arguments(
            parameters: $0,
            arguments: $1,
            env: $2,
            index: @core.plus(left: $3, right: 1),
            accum: $4,
            return_type: $50,
            expected_type: $51
          )
      }
  }
visibility
public
core.type-call-type-arguments (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: ZEaE9Lq9dXK8ACOPceGSIgKCqXaTiqHY_2c4WCYjkMM
content hash: oSgSZX7hHMQ5POBvV3ZfOZE3hkidkfLN-E9eF21ESPA