Giter Site home page Giter Site logo

Comments (8)

agocke avatar agocke commented on July 1, 2024 2

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.

sbomer avatar sbomer commented on July 1, 2024

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.

jaredpar avatar jaredpar commented on July 1, 2024

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.

alrz avatar alrz commented on July 1, 2024

For comparison, F# encodes the mapping itself in attributes (sharplab.io) although it annotates the properties instead of fields.

from roslyn.

agocke avatar agocke commented on July 1, 2024

@jaredpar Should we make this issue a draft spec, or would you prefer something in dotnet/designs?

from roslyn.

sbomer avatar sbomer commented on July 1, 2024

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.

sbomer avatar sbomer commented on July 1, 2024

I opened a broader version of the proposal at #73920. Happy to move it elsewhere if desired.

from roslyn.

sbomer avatar sbomer commented on July 1, 2024

Closing this - we can continue discussion in the broader proposal that's a superset of this one: #73920.

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.