-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix double-free and compiler crash (#1414)
## Summary * fix a double-free issue when assigning to `sink` parameters of instantiated generic tuple type * fix a compiler crash when passing an empty `seq`, `array`, or `set` construction to a generic instantiation receiver type Fixes #1415. ## Details Post-match fitting didn't consider generic tuple instantiations when applying implicit conversions, meaning that the `nkHiddenSubConv` or `nkHiddenStdConv` inserted earlier by `sigmatch` stayed. This led to two issues: * `nkStmtListExpr`s of empty container type didn't have their types fixed properly, causing crashes when the empty type reached into the MIR phase * a conversion between `sink T` and `T` is considered an rvalue conversion by `proto_mir`, which resulted in assignments involving these implicit conversions effectively being *shallow* assignments (and thus double frees) Skipping `tyGenericInst` and `tyAlias` (for good measure) makes sure the implicit conversion is collapsed when the destination type is a generic instantiation, fixing both issues. A test is added for both.
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/lang_types/tuples/tsink_generic_tuple_assignment.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
discard """ | ||
description: ''' | ||
Regression test for a bug where assigning a ``sink`` generic tuple type | ||
to a variable of non-``sink`` type led to the value being shallow copied. | ||
''' | ||
matrix: "--showir:mir_in:test --hints:off" | ||
nimout: ''' | ||
-- MIR: test | ||
scope: | ||
def x: sink Tuple[system.int] | ||
def v: Tuple[system.int] | ||
v = sink x | ||
-- end | ||
''' | ||
""" | ||
|
||
type Tuple[T] = (T, T) | ||
|
||
proc test(x: sink Tuple[int]) = | ||
var v: Tuple[int] | ||
v = x # this assignment was considered to involve a conversion | ||
|
||
test default(Tuple[int]) |