| 232 | * declared `function`, and this wins over any Element conjunct. The engine |
| 233 | * (strict mode) reports `expected-function` when a symbol declared with a |
| 234 | * non-function type is applied, so declaring such a variable `complex` makes |
| 235 | * the whole entry fail Stage 1. A `DirichletGroup` membership, for example, |
| 236 | * falls through `inferType` to `complex`, yet `chi` is a function. |
| 237 | */ |
| 238 | export function variableTypes(e: Entry): Record<string, string> { |
| 239 | const types: Record<string, string> = {}; |
| 240 | const applied = new Set<string>(); |
| 241 | const vars = new Set(e.variables); |
| 242 | const walk = (x: unknown): void => { |
| 243 | if (!Array.isArray(x)) return; |
| 244 | if (typeof x[0] === 'string' && vars.has(x[0])) applied.add(x[0]); |
| 245 | if (x[0] === 'Element' && typeof x[1] === 'string' && x.length >= 3) |
| 246 | types[x[1]] ??= inferType(x[2]); |
| 247 | for (const y of x) walk(y); |
| 248 | }; |
| 249 | walk(e.assumptions); |