Skip to content

infer: don't trust a transiently void call when accepting 'return void_expr' - #3894

Merged
borisbat merged 1 commit into
GaijinEntertainment:masterfrom
profelis:master
Aug 28, 2026
Merged

infer: don't trust a transiently void call when accepting 'return void_expr'#3894
borisbat merged 1 commit into
GaijinEntertainment:masterfrom
profelis:master

Conversation

@profelis

Copy link
Copy Markdown
Collaborator

PR #3861 accepts 'return void_expr' and resolves a bare auto result to void through the regular generic-infer machinery. That commit is irreversible, and the subexpression's void type is not always final: a [generic] instance still pending [constant_expression] folding is an empty void function for a pass or two (its body sits under 'static_if !typeinfo is_argument(...)'), and the transform then swaps the call for a clone that briefly carries the stale void type with no function bound. Locking the caller's auto result to void off that state, or lowering the return to { expr; return; }, poisons the function for good; every pre-#3861 compiler simply erred on that pass and retried.

Add InferTypes::isVoidReturnValueSettled: a void-typed ExprCallFunc only counts once its callee settled (builtin, fully inferred, or from an already compiled module; a call with no function bound never does). Until then the return defers with not-resolved-yet, same as any other unresolved subexpression. Non-call void subexpressions (block invokes, etc.) are unaffected.

Adds a regression test: a bare-auto function returning calls to a [generic, constant_expression] function must infer the folded instance's type, not void.

Copilot AI lite review requested due to automatic review settings August 28, 2026 08:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens return-type inference around the recently-added support for return <void_expr> by preventing transient “void-typed” call expressions (e.g., during constant-expression folding / call transforms) from irreversibly pinning a bare auto result type to void or triggering early lowering.

Changes:

  • Adds InferTypes::isVoidReturnValueSettled and uses it to gate both (a) accepting return void_expr for bare-auto result inference and (b) lowering return void_expr into { void_expr; return; }.
  • Updates the ExprReturn inference path to defer with not_resolved_yet_expression_type when a void-typed call’s callee is not yet settled/bound.
  • Adds a regression test covering a [generic, constant_expression] scenario where a call is transiently void until folding finalizes its type.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/language/return_void_expression.das Adds regression coverage for transiently-void generic calls not poisoning bare-auto return inference.
src/ast/ast_infer_type.cpp Gates the return void_expr lowering on the new “void return value settled” predicate.
src/ast/ast_infer_type_helper.cpp Introduces isVoidReturnValueSettled and uses it to defer inference when a void-typed call is transient/unsettled.
include/daScript/ast/ast_infer_type.h Declares the new InferTypes::isVoidReturnValueSettled helper.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ast/ast_infer_type_helper.cpp
Copilot AI review requested due to automatic review settings August 28, 2026 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/ast/ast_infer_type_helper.cpp Outdated
…d_expr'

PR GaijinEntertainment#3861 accepts 'return void_expr' and resolves a bare auto result to void
through the regular generic-infer machinery. That commit is irreversible, and
the subexpression's void type is not always final: a [generic] instance still
pending [constant_expression] folding is an empty void function for a pass or
two (its body sits under 'static_if !typeinfo is_argument(...)'), and the
transform then swaps the call for a clone that briefly carries the stale void
type with no function bound. Locking the caller's auto result to void off that
state, or lowering the return to { expr; return; }, poisons the function for
good; every pre-GaijinEntertainment#3861 compiler simply erred on that pass and retried.

Add InferTypes::isVoidReturnValueSettled: a void-typed ExprCallFunc only
counts once its callee settled (builtin, fully inferred, or from an already
compiled module; a call with no function bound never does). Until then the
return defers with not-resolved-yet, same as any other unresolved
subexpression. Non-call void subexpressions (block invokes, etc.) are
unaffected.

Adds a regression test: a bare-auto function returning calls to a
[generic, constant_expression] function must infer the folded instance's
type, not void.
Copilot AI review requested due to automatic review settings August 28, 2026 09:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@borisbat
borisbat merged commit 60b55b7 into GaijinEntertainment:master Aug 28, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants