-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fixes #4799, varargs now can accept polymorphic types #7550
Conversation
compiler/ccgexprs.nim
Outdated
@@ -347,7 +347,8 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = | |||
else: | |||
useStringh(p.module) | |||
linefmt(p, cpsStmts, | |||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len_0);$n", | |||
#"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len_0);$n", | |||
"$1 = $2;$n", |
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.
How is this correct? C arrays have no assignment operator.
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.
- because of bug varags broken with polymorphic types #4799, this 'else' branch never executed anymore.
- all other Nim types of varargs are not handled through this 'else' branch. they are handled somewhere else. Only ref object are handled by this 'else' branch. Ordinary object and ptr object are not handled here.
- I also tried various openArray, they also never handled by this 'else' branch
- the above code also not a C array assignment, but plain pointer assignment.
- the transform part already transform the AST into a series of single pointer assignment(s), not a sequence of pointers assignment anymore.
- because of this reasons, the memcpy no longer needed, at least we haven't encountered other use case of this
else
branch besides simple pointer assignment.
"Len_0" also not used anymore, bad codegen here.
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.
perhaps a clear annotation/comment for this else
branch sufficient, until another bug comes up?
Does it work with an explicit |
I found three more issues with this case:
remind myself:
|
compiler/sigmatch.nim
Outdated
@@ -2000,6 +2000,13 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, | |||
m.baseTypeMatch = true | |||
else: | |||
result = userConvMatch(c, m, base(f), a, arg) | |||
# bug #4799, varargs accepting subtype relation object | |||
if result.isNil and r == isSubtype: |
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.
The check for r == isSubtype
needs to be moved above userConvMatch
, I think.
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.
#7600 and #7601 already merged, now I can focus on this one. and this is the new todo list:
|
@@ -0,0 +1,24 @@ | |||
discard """ |
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.
Perhaps this bug doesn't deserve so many separate test cases (they slow down the execution of the test suite a little bit).
The alternative would be to use the accept
/reject
approach seen here:
https://github.com/nim-lang/Nim/blob/devel/tests/cpp/tcovariancerules.nim#L168
tests/typerel/t4799.nim
Outdated
var b = Bike[int](tire: 2) | ||
|
||
reject: | ||
echo testVehicle b, c, v |
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.
Wrong test, needs to be
reject:
echo testVehicle(b, c, v)
tests/typerel/t4799.nim
Outdated
var b = Bike(tire: 2) | ||
|
||
reject: | ||
echo testVehicle b, c, v |
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.
same problem.
tests/typerel/t4799.nim
Outdated
var pgb = PGBike[int](tire: 2) | ||
|
||
reject: | ||
echo testVehicle pgb, pgc |
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.
same problem.
tests/typerel/t4799.nim
Outdated
var rb = RBike(tire: 2) | ||
|
||
reject: | ||
echo testVehicle rb, rc |
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.
same problem.
I'm accepting this but in the future please add more tests that should fail the type checker. A language where everything has a valid interpretation is a language that doesn't detect mistakes. |
No description provided.