-
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.
Nonref object inheritance now hints and converts to base in varargs a…
…nd on assignment
- Loading branch information
Showing
8 changed files
with
69 additions
and
82 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
discard """ | ||
cmd: "nim c --hint[Conf]:off --verbosity:0 $file" | ||
nimout: ''' | ||
Hint: 'Derived()' implicitly converted to 'Base' [tnonref_inheritance_conversion.nim(30, 13)] [ImplicitObjConv] | ||
Hint: 'Derived()' implicitly converted to 'Base' [tnonref_inheritance_conversion.nim(30, 32)] [ImplicitObjConv] | ||
Hint: 'a' implicitly converted to 'Base' [tnonref_inheritance_conversion.nim(32, 7)] [ImplicitObjConv] | ||
Hint: 'b' implicitly converted to 'Base' [tnonref_inheritance_conversion.nim(36, 1)] [ImplicitObjConv] | ||
''' | ||
""" | ||
|
||
|
||
type | ||
Base {.inheritable.} = object | ||
field: int | ||
|
||
Derived = object of Base | ||
field2: int | ||
field3: int | ||
Derived2 = object of Base | ||
|
||
proc test(args: varargs[Base]) = | ||
for x in args: | ||
assert x.field == 0 | ||
|
||
proc test2(base: var Base) = base.field = 400 | ||
|
||
var a: Derived = Derived(Base()) | ||
a = Derived(Base(Derived2())) | ||
test(Derived(), Base(), Derived()) | ||
a.field2 = 300 | ||
test2(a) | ||
assert a.field == 400 | ||
assert a.field2 == 300 | ||
var b = Derived2(field: 800) | ||
b.test2() | ||
assert b.field == 400 | ||
|
||
|
||
|
||
block: | ||
type | ||
Base = ref object of RootObj | ||
field: int | ||
Derived = ref object of Base | ||
field2: int | ||
Derived2 = ref object of Base | ||
|
||
var a: Base = Derived() | ||
assert Derived(a) is Derived | ||
doAssertRaises(ObjectConversionDefect): discard Derived2(a)[] | ||
doAssertRaises(ObjectConversionDefect): discard Base(Derived2()).Derived | ||
assert Base(Derived()) is Base | ||
assert Derived2(Base(Derived2())) is Derived2 | ||
assert Derived(Base(Derived())) is Derived |