Comments (8)
Here's the most straightforward proposal I could think of: we simply copy the annotation from a primary constructor parameter to the generated field/property if possible.
More precisely, I think the proposal is to copy the attributes if compatible with the AttributeTargets. My understanding is that AttributeTargets aren't actually enforced by the runtime, so it is up to the compiler whether or not to respect them.
we simply copy the annotation from a primary constructor parameter to the generated field/property if possible.
I think the proposal is broader than just primary constructors, right? From broader context, I think the goal would be, for any "compiler-hoisted variable", if the source is a legal attribute target, and the destination is a legal attribute target, and the AttributeTargets
on the attribute allow the attribute to appear on the target, the compiler would place an equivalent attribute on the corresponding compiler-generated variable.
from roslyn.
I think the proposal is broader than just primary constructors, right?
Yes, I agree it makes sense to extend the proposal to all cases like you described. I don't know all the cases, but I can at least think of the following:
- parameters of async/iterator methods
- method parameters captured by a lambda or local function
from roslyn.
I agree we need a broader proposal here vs a specific one for primary constructors. Otherwise we will be back here for closures, records, etc ... Think the better path forward is a broader proposal that lets the IL linker get the info it needs without constraining the compiler from evolving its emit approach
from roslyn.
For comparison, F# encodes the mapping itself in attributes (sharplab.io) although it annotates the properties instead of fields.
from roslyn.
@jaredpar Should we make this issue a draft spec, or would you prefer something in dotnet/designs
?
from roslyn.
I just realized C# already supports [property: ...]
syntax for annotating record primary constructor parameters, so I don't think we need to consider record types here. That's helpful because it means we don't need to define behavior that affects the public API for primary constructor parameters (which I think would have to be a language spec?).
Are the implicit type parameters of nested types considered an implementation detail, or behavior specified by the language? For example, this prints System.Int32
:
G<int>.N.M();
class G<T> {
public class N {
public static void M() {
foreach (var p in typeof(N).GetGenericArguments())
Console.WriteLine(p);
}
}
}
from roslyn.
I opened a broader version of the proposal at #73920. Happy to move it elsewhere if desired.
from roslyn.
Closing this - we can continue discussion in the broader proposal that's a superset of this one: #73920.
from roslyn.
Related Issues (20)
- Overridden != and == do not affect nullability HOT 1
- It looks like PEEventSymbol's constructor assumes that we always have both accessors.
- Long-running IAsyncEnumerable<T> leaks the last seen enumerated value. HOT 4
- Roslyn 4.10.0 does not compile for .NET 6 HOT 3
- [Automated] PRs inserted in VS build feature.debugger.main-35014.68
- Roslyn JSON detection marks strings as JSON even if StringSyntaxAttribute says it's not.
- Visual Basic double to integer conversion tests stopped working in .NET 9 Preview 5 HOT 2
- Source Generators referencing nuget packages cannot be debugged in VS HOT 7
- Add fixer when for `params` span overloads are used with Expression selected
- Consider having generators run automatically (when in balanced mode) when a particular SG file is open in the editor. HOT 4
- Clicking 'rerun generator' prevent future edits into the regular text buffer. HOT 7
- `GeneratorDriver.GetRunResult()` should not throw
- Inheritance margin doesn't work well with screen scaling HOT 2
- .AsIncrementalGenerator extension method
- Use target-typed new for all elements in an array or a list
- [Automated] PRs inserted in VS build main-35017.309
- False positive CS4007 "Instance of type 'System.ReadOnlySpan<Buffer10<int>>' cannot be preserved across 'await' or 'yield' boundary" HOT 2
- C# interactive window does not open after the last Visual Studio Community 2022 Update HOT 4
- Remove IBuiltInAnalyzer.OpenFileOnly
- Move static members has incorrect formatting after moving to nested type
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.