1 def@(nodes MethodDefinition traits) inferenceRule
3 def selector := def selector asInferenceRule.
7 node@(nodes Node traits) inferTypesIn: namespace
8 "Assigns a type for the node as determined through propagation of
9 existing type information and hints."
14 node@(nodes Node traits) inferTypes
16 node inferTypesIn: lobby literalType
19 _@(nodes ImplicitArgument traits) inferTypesIn: namespace
24 ann@(nodes Annotation traits) inferTypesIn: namespace
26 ann type := ann value inferTypesIn: namespace
29 message@(nodes Message traits) inferTypesIn: namespace
31 message type == Types Any
33 [message type := message selector inferOn:
35 collect: #(_ inferTypesIn: namespace) `er)]
37 [message arguments do: #(_ inferTypesIn: namespace) `er.
41 opts@(nodes OptionalKeywords traits) inferTypesIn: namespace
43 msgType := opts message inferTypes.
44 opts arguments do: #(_ inferTypesIn: namespace) `er.
45 opts type == Types Any
46 ifTrue: [opts type := msgType]
50 paren@(nodes Parenthesis traits) inferTypesIn: namespace
52 paren statements do: #(_ inferTypesIn: namespace) `er.
53 paren type == Types Any /\ [paren statements isNotEmpty]
54 ifTrue: [paren type := paren statements last type]
58 var@(nodes Variable traits) inferTypesIn: namespace
63 block@(nodes Block traits) inferTypesIn: namespace
65 block localVariables do: #(_ inferTypesIn: namespace) `er.
66 resultType := Types Any.
67 "TODO: handle Return with a Union operation."
69 [| :statement | resultType := statement inferTypesIn: namespace].
70 block type == Types Any
72 [block type := Types Block
73 from: (block inputVariables collect: #type `er)
78 array@(nodes Array traits) inferTypesIn: namespace
80 array statements do: #(_ inferTypesIn: namespace) `er.
81 array type == Types Any
83 [array type := Types Array of:
85 inject: Types None into: [| :x :y | x union: y type])]
89 obj@(Root traits) literalTypeIn: _
91 Types Singleton of: obj
94 literal@(nodes Literal traits) inferTypesIn: namespace
96 literal type == Types Any
97 ifTrue: [literal type := literal value literalTypeIn: namespace]
98 ifFalse: [literal type]
101 load@(nodes LoadVariable traits) inferTypesIn: _
103 load type == Types Any
104 ifTrue: [load type := load variable type]
108 nodes define: #TypeMismatch &parents: {Warning} &slots: {#source. #target}.
110 tm@(nodes TypeMismatch traits) from: source to: target causedBy: description
112 (tm newDescription: description) `>> [source := source. target := target. ]
115 store@(nodes StoreVariable traits) signalTypeMismatch
120 causedBy: 'Type mismatch in assignment to local variable: '
121 ; store variable name name "; ' type:' ; store variable type printString ; ' New type: ' ; store value type printString") signal
124 store@(nodes StoreVariable traits) inferTypesIn: namespace
126 store value inferTypesIn: namespace.
127 (store variable type subsumes: store value type)
128 ifFalse: [store signalTypeMismatch].
129 store type == Types Any
130 ifTrue: [store type := store value type]
131 ifFalse: [store type]
134 return@(nodes Return traits) inferTypesIn: namespace
136 return value inferTypesIn: namespace.
137 return type == Types Any
138 ifTrue: [return type := return value type]
139 ifFalse: [return type]