Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/design/specs/Ecma-335-Augments.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This is a list of additions and edits to be made in ECMA-335 specifications. It
- [Creating arrays using newobj](#creating-arrays-using-newobj)
- [API documentation](#api-documentation)
- [Debug Interchange Format](#debug-interchange-format)
- [Instance construction](#instance-construction)
- [Type initialization](#type-initialization)

## Signatures

Expand Down Expand Up @@ -1102,3 +1104,19 @@ The incorrect description of `System.Array.Initialize` API in section "II.13.2 I
## Debug Interchange Format

The Debug Interchange Format described in partition V is superseded by the [Portable PDB Format](PortablePdb-Metadata.md).

## Instance construction

The following is added to the section "II.10.5.1 Instance constructor":

> Instance constructors shall not be executed multiple times for a single object instance. Explicit calls to constructors on object instances from user code are only permitted when calling instance constructors of the base type inside of instance constructors of the derived type.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. Try this:

class A
{
    A() : this(1)
    {
    }

    A(int x)
    {
    }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you may want to update the wording in the call instruction verification rules that have the same mistake: "The call instruction can also be used to call an object’s base class constructor, or to initialize a value type location by calling an appropriate constructor, both of which are treated as special cases by verification.".

It may be sufficient to just fix the call verification rules to be more precise instead of duplicating it here.


## Type initialization

The following is added to the section "II.10.5.3 Type initializer":

> Type initializers shall not be called explicitly from user code. Users intending to guarantee the type initializer has been executed shall use the `System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor` method.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type initializers shall not be called explicitly from user code

This contradicts "A type initializer shall be executed exactly once for any given type, unless explicitly
called by user code." in the next chapter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is changed with the next paragraph.


Section "II.10.5.3.1 Type initialization guarantees" is changed so that the guarantee number 3 now states the following:

> A type initializer shall be executed exactly once for any given type, unless the previous attempt resulted in a `System.TypeInitializationException` being thrown at the location that triggered it.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless the previous attempt resulted in a System.TypeInitializationException being thrown at the location that triggered it.

I am not sure what this is trying to say.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a .cctor throws an exception, the type is not marked as initialized so the .cctor will be called again by the runtime until it succeeds.

Copy link
Copy Markdown
Member

@jkotas jkotas Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not correct. If the .cctor throws exception, the runtime won't try to run the .cctor again. The failure is cached.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that, I feel like older versions of legacy Mono might've been non compliant with this cause I recall it being rerun in Unity.