dotnet / dotnet/csharpstandard

Should a distinct array/string be required when an empty array/string is created?

Open
#1,403 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

*(This PR is an action item resulting from a TG discussion on slicing.)*

The Standard currently *requires* that string *literals* in the *same* assembly which have the same value, as determined by string equality (§12.12.8), *must* be represented by the same object (§6.4.5.6). Note this only applies to string literals and not strings created dynamically, and as a single program may consist of multiple assemblies does not mean that the same string literal is the same object everywhere in a program.

It is known that at least one implementation uses a single object for each zero-length array and empty string it creates. In particular taking a slice of an array/string though is to return a “new” object, but in this particular implementation may not do so if the resultant slice is empty.

Questions to answer:

- Does this behavior need to be explicitly allowed by the Standard for such an implementation to be conformant?
- If so should it be?
- Are there other cases where a “new“ object is specified in the Standard but where an implementation can provide all the correct semantics, apart from the object reference being distinct, which should be explicitly supported?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.