Module: Jade::Frontend::SemanticAnalysis::KeyedCall

Extended by:
Helper, KeyedCall
Included in:
KeyedCall
Defined in:
lib/jade/frontend/semantic_analysis/keyed_call.rb,
lib/jade/frontend/semantic_analysis/keyed_call/validation.rb

Overview

Lowers ‘Foo(name: x, age: y)` into a positional FunctionCall:

- struct constructor: FunctionCall(Foo, [x, y]) ordered by struct fields
- keyed variant:      FunctionCall(V, [{a: x, b: y}]) anon record arg

Defined Under Namespace

Modules: Validation

Instance Method Summary collapse

Methods included from Helper

analyze_duplicate_fields, analyze_in_parallel, analyze_in_sequence, analyze_node, bind, collect_vars, lookup, validate_type_symbol

Instance Method Details

#analyze(node, registry, scope, entry) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jade/frontend/semantic_analysis/keyed_call.rb', line 11

def analyze(node, registry, scope, entry)
  node => AST::KeyedCall(callee:, fields:)

  callee_r = analyze_node(callee, registry, scope, entry)
  callee_resolved = callee_r.node
  constructor = constructor_symbol(callee_resolved, registry)
  parent = constructor && registry.lookup(constructor.parent)

  fields_r = analyze_in_parallel(fields, registry, scope, entry)
  fields_resolved = fields_r.node

  validation_errors = Validation.errors(
    node, fields_resolved, parent, constructor, registry, entry,
  )

  lowered = lower(node, callee_resolved, fields_resolved, parent, constructor, registry)

  Result[
    lowered,
    callee_r.errors + fields_r.errors + validation_errors,
    scope,
  ]
end