Skip to content

C# in by val tiebreaker #3949

Closed
Closed

Description

@BillWagner

In C# 7.2, these methods cause an ambiguity:

static void M(S arg);
static void M(in S arg);

This will be fixed in the 7.3 timeframe. The by value (1st in the example above) is better than the in reference version. This will not be a new article, but will require updates to Reference semantics with value types and affect the corresponding VB topics.

This feature will be delivered as a bug fix to C# 7.2. That means a machine with an updated compiler will use the new behavior. However, a machine that has not been updated will have the old 7.2 behavior.

The LDM notes and the feature spec will have details on this behavior.

Feature spec is: dotnet/csharplang#945

Activity

  1. added this to the milestone on Dec 18, 2017
  2. jcouv commented on Jan 22, 2018

    @jcouv
    Contributor

    I think this tie-breaker is only applicable to C#. VB doesn't know how to deal with in.
    @OmarTawfik can confirm.

  3. OmarTawfik commented on Jan 23, 2018

    @OmarTawfik

    @jcouv Yes. Tie breaker is C# specific. VB sees in parameters as references, and can use them where safety isn't an issue. For example, you can pass an in argument from VB by ref to a C# method, but you cannot override a base in method from a parent C# type.
    This is the tie breaker PR: dotnet/roslyn#23122
    VB Examples here: https://github.com/OmarTawfik/roslyn/blob/master/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/InAttributeModifierTests.vb

  4. changed the title [-]C# and VB `in` by val tiebreaker[/-] [+]C# `in` by val tiebreaker[/+] on Jan 23, 2018
  5. BillWagner commented on Jan 23, 2018

    @BillWagner
    MemberAuthor

    Updated title based on @jcouv and @OmarTawfik comments.

  6. BillWagner commented on Feb 28, 2018

    @BillWagner
    MemberAuthor

    I'm going to expand the scope of this somewhat. Looking at the content, I believe a number of locations were missed when in was added as a modifier to method arguments. I'll update those to mention in, and update the language reference on in and ref to explain the tiebreaker rule (and note that the rule only applies as of 7.3. In 7.2 the method call is ambiguous.

  7. BillWagner commented on Mar 2, 2018

    @BillWagner
    MemberAuthor

    PR #4534 does the background work to add discussion of the in modifier where previously the out and ref modifiers were discussed without mention of in.

    The new tiebreaker rule will come in a separate PR.

  8. modified the milestones: , Sprint 132 (2/24/18 - 3/16/18) on Mar 13, 2018
  9. added and removed on Mar 13, 2018
  10. modified the milestones: Sprint 132 (2/24/18 - 3/16/18), on Mar 20, 2018
  11. added a commit that references this issue on Mar 23, 2018
    a11be50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions