Skip to content

Commit

Permalink
Change ordering to simplify adding methods to type in conditional mod…
Browse files Browse the repository at this point in the history
…ules.
  • Loading branch information
lerno committed Jan 6, 2025
1 parent 5fa6ecf commit 51e0e5e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- Fix not freeing a zero length String
- Macros with trailing bodys aren't allowed as the single statement after a while loop with no body #1772.
- Deref subscripts as needed for macro ref method arguments. #1789
- Change ordering to simplify adding methods to type in conditional modules.

### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ typedef enum
ANALYSIS_MODULE_TOP,
ANALYSIS_IMPORTS,
ANALYSIS_REGISTER_GLOBAL_DECLARATIONS,
ANALYSIS_INCLUDES,
ANALYSIS_REGISTER_CONDITIONAL_UNITS,
ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS,
ANALYSIS_METHODS_REGISTER,
ANALYSIS_METHODS_REGISTER_GENERIC,
ANALYSIS_INCLUDES,
ANALYSIS_METHODS_INCLUDES,
ANALYSIS_METHODS_INCLUDES_GENERIC,
ANALYSIS_REGISTER_CONDITIONAL_UNITS,
ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS,
ANALYSIS_METHODS_CONDITIONAL,
ANALYSIS_METHODS_CONDITIONAL_GENERIC,
ANALYSIS_POST_REGISTER,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/sema_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ bool sema_unresolved_type_is_generic(SemaContext *context, TypeInfo *type_info)
if (type_info->resolve_status == RESOLVE_DONE) return false;
if (type_info->kind != TYPE_INFO_IDENTIFIER) return false;
if (type_info->subtype != TYPE_COMPRESSED_NONE) return false;
Decl *decl = sema_resolve_symbol(context, type_info->unresolved.name, type_info->unresolved.path, type_info->span);
Decl *decl = sema_find_path_symbol(context, type_info->unresolved.name, type_info->unresolved.path);
if (!decl) return false;
if (decl->decl_kind != DECL_TYPEDEF) return false;
if (decl->resolve_status == RESOLVE_DONE) return false;
if (decl->typedef_decl.is_func) return false;
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/semantic_analyser.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,27 @@ void sema_analyze_stage(Module *module, AnalysisStage stage)
case ANALYSIS_REGISTER_GLOBAL_DECLARATIONS:
sema_analysis_pass_register_global_declarations(module);
break;
case ANALYSIS_INCLUDES:
sema_analysis_pass_process_includes(module);
break;
case ANALYSIS_REGISTER_CONDITIONAL_UNITS:
sema_analysis_pass_register_conditional_units(module);
break;
case ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS:
sema_analysis_pass_register_conditional_declarations(module);
break;
case ANALYSIS_METHODS_REGISTER:
sema_analysis_pass_process_methods(module, false);
break;
case ANALYSIS_METHODS_REGISTER_GENERIC:
sema_analysis_pass_process_methods(module, true);
break;
case ANALYSIS_INCLUDES:
sema_analysis_pass_process_includes(module);
break;
case ANALYSIS_METHODS_INCLUDES:
sema_analysis_pass_process_methods(module, false);
break;
case ANALYSIS_METHODS_INCLUDES_GENERIC:
sema_analysis_pass_process_methods(module, true);
break;
case ANALYSIS_REGISTER_CONDITIONAL_UNITS:
sema_analysis_pass_register_conditional_units(module);
break;
case ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS:
sema_analysis_pass_register_conditional_declarations(module);
break;
case ANALYSIS_METHODS_CONDITIONAL:
sema_analysis_pass_process_methods(module, false);
break;
Expand Down
15 changes: 15 additions & 0 deletions test/test_suite/methods/method_extension_in_conditional_module.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module std::core::env;
const bool FOO = true;

module foo @if(env::FOO);
struct Foo { int a; }

module bar;
import std, foo;

fn void Foo.baz(self) {}

fn int main()
{
return 0;
}

0 comments on commit 51e0e5e

Please sign in to comment.