diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-01-01 17:40:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-01 17:40:04 +0000 |
| commit | 8d400f43fd958ae05cd5aaf22993ee73b6347bff (patch) | |
| tree | a5603331bd01966635b144012ab16801398d5dc6 /src | |
| parent | 7248958fcdb4fcb009a85b73787590aec2113d87 (diff) | |
| parent | f2f952b344b076c17281e0e77195a27d94f58919 (diff) | |
Merge pull request #4607 from zen3ger/parapoly-proc-fixes
Fix crash when proc return type is undeclared parapoly variable
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_type.cpp | 9 | ||||
| -rw-r--r-- | src/checker.hpp | 1 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 13a6125ca..44108ccbe 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2440,8 +2440,12 @@ gb_internal bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc bool success = true; isize specialization_count = 0; Type *params = check_get_params(c, c->scope, pt->params, &variadic, &variadic_index, &success, &specialization_count, operands); - Type *results = check_get_results(c, c->scope, pt->results); + bool no_poly_return = c->disallow_polymorphic_return_types; + c->disallow_polymorphic_return_types = c->scope == c->polymorphic_scope; + // NOTE(zen3ger): if the parapoly scope is the current proc's scope, then the return types shall not declare new poly vars + Type *results = check_get_results(c, c->scope, pt->results); + c->disallow_polymorphic_return_types = no_poly_return; isize param_count = 0; isize result_count = 0; @@ -3383,6 +3387,9 @@ gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, T } Type *t = alloc_type_generic(ctx->scope, 0, token.string, specific); if (ctx->allow_polymorphic_types) { + if (ctx->disallow_polymorphic_return_types) { + error(ident, "Undeclared polymorphic parameter '%.*s' in return type", LIT(token.string)); + } Scope *ps = ctx->polymorphic_scope; Scope *s = ctx->scope; Scope *entity_scope = s; diff --git a/src/checker.hpp b/src/checker.hpp index 036990f29..3951fcefe 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -522,6 +522,7 @@ struct CheckerContext { bool in_enum_type; bool collect_delayed_decls; bool allow_polymorphic_types; + bool disallow_polymorphic_return_types; // NOTE(zen3ger): no poly type decl in return types bool no_polymorphic_errors; bool hide_polymorphic_errors; bool in_polymorphic_specialization; |