Fix type resolution order
f40263424c23237031dcdf90658b51b82908bec0db4b431f461a49451bb790f7
This allows for constants from other modules to be used inside constant expressions.
1 parent
359694c2
lib/std/lang/resolver.rad
+16 -15
| 6461 | 6461 | if not decl.wildcard { |
|
| 6462 | 6462 | try resolveUse(res, node, decl); |
|
| 6463 | 6463 | } |
|
| 6464 | 6464 | } |
|
| 6465 | 6465 | } |
|
| 6466 | - | // Phase 3: Process submodule declarations -- recurses into child modules. |
|
| 6466 | + | // Phase 3: Bind function signatures so that function references are |
|
| 6467 | + | // available in constant and static initializers. |
|
| 6468 | + | for node in block.statements { |
|
| 6469 | + | if let case ast::NodeValue::FnDecl(decl) = node.value { |
|
| 6470 | + | try resolveFnDecl(res, node, decl); |
|
| 6471 | + | } |
|
| 6472 | + | } |
|
| 6473 | + | // Phase 4: Process constants before submodules, so that child modules |
|
| 6474 | + | // can reference parent constants via `super::`. |
|
| 6475 | + | for node in block.statements { |
|
| 6476 | + | if let case ast::NodeValue::ConstDecl(_) = node.value { |
|
| 6477 | + | try infer(res, node); |
|
| 6478 | + | } |
|
| 6479 | + | } |
|
| 6480 | + | // Phase 5: Process submodule declarations -- recurses into child modules. |
|
| 6467 | 6481 | // Child modules may trigger on-demand type resolution via |
|
| 6468 | 6482 | // [`ensureNominalResolved`] which switches to the declaring module's |
|
| 6469 | 6483 | // scope. |
|
| 6470 | 6484 | for node in block.statements { |
|
| 6471 | 6485 | if let case ast::NodeValue::Mod(decl) = node.value { |
|
| 6472 | 6486 | try resolveModDecl(res, node, decl); |
|
| 6473 | 6487 | } |
|
| 6474 | 6488 | } |
|
| 6475 | - | // Phase 3b: Process wildcard imports after submodules are resolved, |
|
| 6489 | + | // Phase 5b: Process wildcard imports after submodules are resolved, |
|
| 6476 | 6490 | // so that transitive re-exports (pub use foo::*) are visible. |
|
| 6477 | 6491 | for node in block.statements { |
|
| 6478 | 6492 | if let case ast::NodeValue::Use(decl) = node.value { |
|
| 6479 | 6493 | if decl.wildcard { |
|
| 6480 | 6494 | try resolveUse(res, node, decl); |
|
| 6481 | 6495 | } |
|
| 6482 | 6496 | } |
|
| 6483 | 6497 | } |
|
| 6484 | - | // Phase 4: Bind function signatures so that function references are |
|
| 6485 | - | // available in constant and static initializers. |
|
| 6486 | - | for node in block.statements { |
|
| 6487 | - | if let case ast::NodeValue::FnDecl(decl) = node.value { |
|
| 6488 | - | try resolveFnDecl(res, node, decl); |
|
| 6489 | - | } |
|
| 6490 | - | } |
|
| 6491 | - | // Phase 5: Process constants. |
|
| 6492 | - | for node in block.statements { |
|
| 6493 | - | if let case ast::NodeValue::ConstDecl(_) = node.value { |
|
| 6494 | - | try infer(res, node); |
|
| 6495 | - | } |
|
| 6496 | - | } |
|
| 6497 | 6498 | // Phase 6: Resolve type bodies (record fields, union variants). |
|
| 6498 | 6499 | try resolveTypeBodies(res, block); |
|
| 6499 | 6500 | // Phase 7: Process all other declarations (statics, etc.). |
|
| 6500 | 6501 | for stmt in block.statements { |
|
| 6501 | 6502 | // TODO: This error should propagate, since we catch errors in the `resolveModule` entry point. |