-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nonref object inheritance hints and converts to base in varargs a… #74
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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,53 @@ | ||
discard """ | ||
cmd: "nim check --hints:off $file" | ||
action: reject | ||
nimout: ''' | ||
tinheritance_arrays.nim(20, 18) Error: type mismatch: got <B> but expected 'A = object' | ||
tinheritance_arrays.nim(20, 23) Error: type mismatch: got <C> but expected 'A = object' | ||
tinheritance_arrays.nim(21, 18) Error: type mismatch: got <B> but expected 'C = object' | ||
tinheritance_arrays.nim(21, 23) Error: type mismatch: got <A> but expected 'C = object' | ||
tinheritance_arrays.nim(22, 23) Error: type mismatch: got <A> but expected 'B = object' | ||
''' | ||
""" | ||
|
||
|
||
block: # Value test | ||
type | ||
A = object of RootObj | ||
B = object of A | ||
C = object of A | ||
|
||
discard [A(), B(), C()] | ||
discard [C(), B(), A()] | ||
discard [B(), B(), A()] | ||
discard [B(), B(), B()] | ||
discard [A(), A(), A()] | ||
|
||
block: # ref test | ||
type | ||
A = ref object of RootObj | ||
B = ref object of A | ||
C = ref object of A | ||
|
||
discard [A(), B(), C()] | ||
discard [C(), B(), A()] | ||
discard [B(), B(), A()] | ||
discard [B(), B(), B()] | ||
discard [A(), A(), A()] | ||
|
||
block: # ptr test | ||
type | ||
A = object of RootObj | ||
B = object of A | ||
C = object of A | ||
|
||
template make(t: typedesc): ptr t = | ||
let res = createU(t) | ||
res[] = t() | ||
res | ||
|
||
discard [make A, make B, make C] | ||
discard [make C, make B, make A] | ||
discard [make B, make B, make A] | ||
discard [make B, make B, make B] | ||
discard [make A, make A, make A] |
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,71 @@ | ||
discard """ | ||
cmd: "nim c --hint[Conf]:off --verbosity:0 $file" | ||
nimout: ''' | ||
Hint: Implicit conversion: Receiver 'Base' will not receive fields of sub-type 'Derived' [tinheritance_conversion.nim(30, 15)] [ImplicitObjConv] | ||
Hint: Implicit conversion: Receiver 'Base' will not receive fields of sub-type 'Derived' [tinheritance_conversion.nim(30, 34)] [ImplicitObjConv] | ||
Hint: Implicit conversion: Receiver 'Base' will not receive fields of sub-type 'Derived2' [tinheritance_conversion.nim(38, 3)] [ImplicitObjConv] | ||
|
||
''' | ||
""" | ||
|
||
|
||
type | ||
Base {.inheritable.} = object | ||
field: int | ||
|
||
Derived = object of Base | ||
field2: int | ||
field3: int | ||
Derived2 = object of Base | ||
|
||
block: # Value tests | ||
proc test(args: varargs[Base]) = | ||
for x in args: | ||
assert x.field == 0 | ||
|
||
proc test2(base: var Base) = base.field = 400 | ||
proc test3(base: Base) = discard | ||
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 | ||
b.test3() | ||
|
||
|
||
|
||
block: # Ref tests | ||
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 | ||
|
||
block: # Pointer tests | ||
template make(t: typedesc): ptr t = | ||
let res = createU(t) | ||
res[] = t() | ||
res | ||
var a: ptr Base = make(Derived) | ||
assert (ptr Derived)(a) is (ptr Derived) | ||
doAssertRaises(ObjectConversionDefect): discard (ptr Derived2)(a)[] | ||
doAssertRaises(ObjectConversionDefect): | ||
var a = make(Derived2) | ||
discard (ptr Derived)((ptr Base)(a)) | ||
assert (ptr Base)(make(Derived)) is (ptr Base) | ||
assert (ptr Derived2)((ptr Base)(make(Derived2))) is (ptr Derived2) | ||
assert (ptr Derived)((ptr Base)(make(Derived))) is (ptr Derived) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beef331 is the intention with these tests to fold into the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably should be moved to the spec I guess since it's for regression assurance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if you know how to do it now then go for it, otherwise ask @haxscramper when he's about and do it later?
(we can merge this in the meantime)