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
Issue 2789 - Functions overloads are not checked for conflicts #656
Conversation
if (type && f->type && // can be NULL for overloaded constructors | ||
TypeFunction::overloadConflict((TypeFunction *)type, (TypeFunction *)f->type) && | ||
f->type->mod == type->mod && | ||
!isFuncAliasDeclaration()) |
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.
You already do check for mod == mod
in overloadConflict.
Also testing isFuncAliasDeclaration
is much cheaper and should be done
before calling overloadConflict.
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.
Will do.
I'd prefer a separate function for the check. void FuncDeclaration::overloadCheck()
{
for (FuncDeclaration *f = overnext; f; f = f->overnext)
{
// do the check
}
} Then you can call This is also a good opportunity to get rid of that pointless recursion in overloadInsert where all we want |
I'd rather keep them as one function. If I split them up, most of the code will end up duplicated for not a lot of gain. There is plenty of precedent for using flags like this. I don't see what the issue with the recursive call is. I'd prefer to change as little code as possible with each patch, in my experience it reduces conflicts and aids reviewing. I especially don't want to change the flow used in this function because it also involves alias and template overloads. I will have a look at them after this patch is merged, but I'd rather not do too much at once here. |
Ah your right, overloadInsert is polymorph and will switch between different functions. Some unittests that check overloading of functions, aliases and templates would be nice, not sure what works though. |
int TypeFunction::overloadConflict(TypeFunction *t1, TypeFunction *t2) | ||
{ | ||
if (!t1 || !t2) | ||
return t1 != t2; |
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.
Why do I have a conflict if one type is NULL and the other is not?
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.
Typo. And probably useless code anyway, I think I'll replace it with assert(!null)
No, their behavior doesn't need to change. The only modification was to the big test which only applied to functions, the others are handled in other paths. There are problems with aliases and templates (I've got the issue numbers written down somewhere) but I'd like to handle them in a separate patch.
Not much. Overloading with aliases is iirc completely unchecked, and overloading with templates is completely broken. |
Implement rvalue reference for struct literal and construction
Two issues here: - The check in `overloadInsert` is disabled as it can't work until semantic has been run on all overloads. This has been changed so that the check and the actual insertion can be run seperately. - The check is out of date. `Type::covariant` is no longer suitable, as it allows a much wider set of conversions and requires return type covariance, which is not needed for two overloads to conflict. The new function to perform this check is `TypeFunction::overloadConflict`. Fixes issue 2789
LGTM pending final review by @dawgfoto. |
Issue 8321 - std.range.put doesn't work with RefCounted output range
please rebase |
TBH this is so old I don't remember how it works. It will likely need to be redone after @9rnsr's template overloading pulls are merged anyway, so I'm going to close it. |
Two issues here:
overloadInsert
is disabled as it can't work until semantic has been run on all overloads. This has been changed so that the check and the actual insertion can be run seperately.Type::covariant
is no longer suitable, as it allows a much wider set of conversions and requires return type covariance, which is not needed for two overloads to conflict. The new function to perform this check isTypeFunction::overloadConflict
.http://d.puremagic.com/issues/show_bug.cgi?id=2789