Comments (5)
Perhaps a nice solution to this issue would be to override Equals (and GetHashCode) in classes implementing IVariable, and consider them equal if their Region property is the same.
from nrefactory.
Yes, we compare variables by region sometimes in SharpDevelop. However I think having identity for IVariables produces by a single CSharpAstResolver would be nice.
I think implicitly-typed lambdas are the only case where we don't have IVariable identity already.
Now implicitly-typed lambdas are really complex, as the lambda depends on the target type (the delegate to which the lambda is converted), but figuring out the target type might involve overload resolution (for method calls in which the lambda is used as argument), which requires knowledge about the lamdba.
The implementation in NRefactory works like this:
- The lambda resolves to a LambdaResolveResult. The lambda body is not resolved yet (one of the few places where ResolveVisitor deviates from the usual depth-first AST traversal).
- The parent statement is resolved as usual. This might require analyzing the lambda in detail (for example as part of overload resolution). Such analysis happens using LambdaResolveResult.IsValid, where the caller (i.e. the overload resolution algorithm) supplies the parameter types to the lambda body. For every IsValid() call, a nested resolver is constructed for analyzing the lambda using the supplied type assignment. Multiple IsValid() calls may use several nested resolvers, one for each set of parameter types.
- When the resolver reports the conversions that occurred as part of the parent statement (as with any conversions), the results from the nested resolver corresponding to the actually chosen conversion are merged into the main resolver.
- LambdaResolveResult.Body is set to the main resolve result from the chosen nested resolver. I think this is the only place where NRefactory is mutating a ResolveResult (normally all resolve results are immutable). As this step is guaranteed to occur before the resolver returns the LamdbaResolveResult to user code, the mutation shouldn't cause any problems.
Now the issue with LambdaResolveResult.Parameters is that those parameters are still the typeless fake parameters created in step 1 for consumption in step 2. I think I can change step 4 to replace the parameters collection with the actual typed parameters. Though that only explains why there are two different IParameter instances, I have no idea where the third is coming from.
from nrefactory.
I fixed LambdaResolveResult.Parameters to return the typed parameters to user code. This should solve the problem. I initially thought your test was demonstrating 3 different parameter instances, but you were comparing ResolveResult instances, not IParameter instances.
from nrefactory.
FYI, I'm not 100% sure, but I think I saw this behaviour also for explicitly typed lambdas.
from nrefactory.
My thought that I saw the behavior with explicitly typed lambdas was probably wrong and due to the bug you spotted in my test, comparing a ResolveResult to a variable in one case.
from nrefactory.
Related Issues (20)
- Resolving members with CSHarpTypeResolveContext
- The Online Converter untranslates event handler assignments.
- The Online Converter messes up object initializers HOT 11
- DocumentScript.FormatText is called during dispose HOT 1
- ParserError with DataRowVersion HOT 4
- Interpolated Strings: Compiler error when an interpolated string is too long HOT 1
- Make "base" and "this" constructor keywords as identifiers HOT 2
- CreateNewOverrideCompletionData does not get called
- Is it possible to force NRefactory to use .NET 3.5 instead of 4 when analyzing code?
- How to get controllers and actions attributes without using reflection
- Format issue when TextEditorOptions.TabsToSpaces is false
- CodeConverter service not available HOT 3
- An item with the same key has already been added.
- CodeConverter service again not available HOT 15
- Upgrade to latest Cecil HOT 1
- XmlDocumentationProvider - "output char buffer is too small to contain the decoded characters"
- How to implement C# 6.0+ support HOT 4
- How to implement NRefactory HOT 2
- Error on saving the solution HOT 2
- This project should be marked as archived HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nrefactory.