-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #7818, correct internal representation of generic objects array…
… construction (#7824) * defer skiptypes * defer skiptypes for tyRef & tyPtr * remove unneeded skipTypes
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 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
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,45 @@ | ||
discard """ | ||
msg: '''BracketExpr | ||
Sym "array" | ||
Infix | ||
Ident ".." | ||
IntLit 0 | ||
IntLit 2 | ||
BracketExpr | ||
Sym "Vehicle" | ||
Sym "int" | ||
--------- | ||
BracketExpr | ||
Sym "array" | ||
Infix | ||
Ident ".." | ||
IntLit 0 | ||
IntLit 2 | ||
BracketExpr | ||
Sym "Vehicle" | ||
Sym "int" | ||
---------''' | ||
""" | ||
|
||
# bug #7818 | ||
# this is not a macro bug, but array construction bug | ||
# I use macro to avoid object slicing | ||
# see #7712 and #7637 | ||
import macros | ||
|
||
type | ||
Vehicle[T] = object of RootObj | ||
tire: T | ||
Car[T] = object of Vehicle[T] | ||
Bike[T] = object of Vehicle[T] | ||
|
||
macro peek(n: typed): untyped = | ||
echo getTypeImpl(n).treeRepr | ||
echo "---------" | ||
|
||
var v = Vehicle[int](tire: 3) | ||
var c = Car[int](tire: 4) | ||
var b = Bike[int](tire: 2) | ||
|
||
peek([c, b, v]) | ||
peek([v, c, b]) |