Local function hides functions declared in class #2218
Replies: 8 comments
-
As @gafter said -- this is by design. |
Beta Was this translation helpful? Give feedback.
-
I don't think this is by design The point here is, even local function and class function is the same name, it has difference signature. It should be treat as normal overload function |
Beta Was this translation helpful? Give feedback.
-
My point exactly. |
Beta Was this translation helpful? Give feedback.
-
Local functions don't participate in overloads. If the local function is resolved by name the compiler stops there and doesn't attempt to resolve further potential candidates. That is by design. |
Beta Was this translation helpful? Give feedback.
-
It is understandable that currently it works as intended. And it is obvious that it can be fixed as proposed by @Unknown6656 or just refactored with other name. It just wonders me that with a lot of flexibility of C# (sometimes beyond good and evil like omitting type arguments etc.), this overload resolution does not work. If it is not a bug currently, maybe it can be done in future releases as new feature. |
Beta Was this translation helpful? Give feedback.
-
If we make the local function overload with members of the enclosing type, then we might get a different result than we do today. That would be a breaking change, and we would not do it even if we thought it was a good idea. |
Beta Was this translation helpful? Give feedback.
-
@gafter Not saying I want this, just throwing it at the wall. |
Beta Was this translation helpful? Give feedback.
-
Then you'd get into the weird situation of having to know how far the compiler is willing to coerce the type before it becomes "unsuitable" and that could be very tricky to reason about. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
@aka-STInG commented on Tue Feb 12 2019
Version Used:
C# 7.3 (Visual Studio 2017 15.9.6
Steps to Reproduce:
Expected Behavior:
Compilation without errors
Actual Behavior:
error CS1501: No overload for method 'IsSum' takes 2 arguments
@gafter commented on Tue Feb 12 2019
This is by design. The method group contains only one method, which is found in scope.
Moving to
csharplang
repo for any further discussion.Beta Was this translation helpful? Give feedback.
All reactions