Comments (5)
Hey, can i pick this up if possible?
from roslyn.
@DannySliekers i would just work on a fix that resolves exactly the case reported.
from roslyn.
@DannySliekers Absolutely!
from roslyn.
So I did some investigating and found that the issue seems to lie at the removal of the LocalDeclarationStatement, as none of the leading and trailing trivia gets preserved:
For the case of leading trivia i assume we want to include all leading trivia in the fixed code, right?
Example with trivia on same line:
// Code with violation.
/* test */ var builder = ImmutableArray.CreateBuilder<int>();
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable();
// Desired code
/* test */ ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }];
For the case in which the declaration of the builder contains trailing trivia seems to be a little bit more complicated.
This seems like a desired result to me:
// Code with violation.
var builder = ImmutableArray.CreateBuilder<int>(); // test
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable();
//Desired code
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test
If the fix in the code above is desired, there is a case where there would be multiple options of preserving trivia:
var builder = ImmutableArray.CreateBuilder<int>(); // test
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable(); // test2
//Desired code #1?
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test2 // test
//Desired code #2?
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test // test2
Seems to me like there are multiple options in the case of trailing trivia at the declaration of the builder, and I would like to know what would be desirable.
from roslyn.
For the case of leading trivia i assume we want to include all leading trivia in the fixed code, right?
We try to handle reasonable code patterns, and we don't expend effort on uncommon ones.
So, for example, this is not common: /* test */ var builder = ImmutableArray.CreateBuilder<int>();
.
from roslyn.
Related Issues (20)
- Missing nullability warning for spreads of maybe-null collections HOT 1
- Codegen for spreading a null array does not throw NullReferenceException HOT 9
- [Automated] PRs inserted in VS build main-35206.64
- Collection Expression Generated Types miss the [CompilerGenerated] attribute HOT 4
- Stack overflow when compiling incorrectly formed attribute argument string HOT 3
- Partial properties on struct warn about field ordering HOT 1
- [Automated] PRs inserted in VS build main-35207.120
- False positive IDE0001 when using extern alias
- The [InterceptsLocation] attribute generates a different "data" string for big-endian platforms HOT 7
- Synthesized collection types may result in empty unnecessary `<PrivateImplementationDetails>` class HOT 3
- Generator vs xaml generated files (the "*.g.i.cs") HOT 2
- [Automated] PRs inserted in VS build main-35208.78
- Default literals should not contribute their type from initial binding to best-type in nullable analysis
- CA1003 does not take the return value of an event handler into account
- Visual Studio did not auto fill complete after typing Property in VB.net HOT 4
- Fix formatting not using tabs HOT 2
- Refactor "Move type to file" should re-evaluate file header template
- Decompiled sources resolve wrong type.
- C# compiler integration with new System.Runtime.InteropServices.ExtendedLayoutAttribute
- [Automated] PRs inserted in VS build feature.debugger.main-35209.61
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 roslyn.