Code Monkey home page Code Monkey logo

csharpspec's People

Contributors

ljw1004 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpspec's Issues

Incorrect handling of readonly fields in object initializers

The way the specification defines object initializers is incorrect. Specifically, it lowers all initializers into property sets, when this is not always accurate. Fundamentally, object initializers should initialize. The fact that sometimes this may involve assignment should be an implementation detail. The main area where this distinction produces surprising behaviour is in the case of readonly fields. Consider the following program:

using System;
public class Test
{
    public readonly int num;
}

public class Program
{
    public static void Main()
    {
        var test = new Test { num = 1 };
    }
}

This produces the error that you can't assign to the field outside a variable initializer or constructor because it's readonly, despite the fact that the assignment clearly occurs inside an initializer.

The main issue I see with fixing this is interaction with legacy code, e.g. if Test had a meaningful default constructor that set the field. Previously this would have been a fixed value but now callers of Test can mutate it.

Therefore I'd suggest that, strictly in the case where the class declaring the property or field has no user-defined default constructor, and the object initializer does not call a custom constructor, and if a property the property has no user-defined setter, and the field or property is accessible for reading, then the assignment should be permitted.

Several typos

  • in classes.md: method.The should be method. The
  • in conversions.md: the first object and dynamic should be in backticks
  • in documentation-comments.md: training should be trailing (2 times)
  • in expressions.md: arguments.The should be arguments. The
  • in expressions.md: criteria.The should be criteria. The
  • in types.md: 0 <= *c* < 2^96 should be 0 <= c < 2^96

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.