Skip to content

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Oct 11, 2025

Summary

Fix using a terminal expressions as an object construction operand
resulting in incorrect run-time behaviour.

Details

Elimination of unreachable expression didn't handle object constructors
properly, not adding the terminal expression to the resulting statement
list. For example:

  Obj(a: x, b: (stmt; return; 1))
  # was turned into just
  discard x
  # `stmt; return` was erroneously omitted 

Since the surrounding statement was marked as not returning, the lack
of terminator statement caused incorrect MIR to be produced by
mirgen.

The terminal expression is now added to the produced statement list,
and a test is added to make sure eliminating construction expressions
works.

They cover both effects appearing before the terminating
sub-expression and effects part of the terminating sub-expression, for
all three construction expression types.
@zerbina zerbina added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Oct 11, 2025
@saem
Copy link
Collaborator

saem commented Oct 13, 2025

/merge

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Oct 13, 2025
Merged via the queue into nim-works:devel with commit e9ec2f9 Oct 13, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants