Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test plan for "Infer tuple names" aka "tuple projection initializers" (7.1) #18606

Closed
42 of 72 tasks
gafter opened this issue Apr 11, 2017 · 3 comments
Closed
42 of 72 tasks
Assignees
Labels
Area-Compilers Feature - Tuples Tuples Test Test failures in roslyn-CI
Milestone

Comments

@gafter
Copy link
Member

gafter commented Apr 11, 2017

Test plan for "Infer tuple names" aka "tuple projection initializers"

This is a checklist for testing the implementation of dotnet/csharplang#415. I (@gafter) will check items off as I see they are tested.
Items that are checked off but marked with the name of a test have been updated by Julien.

  • We need a specish proposal that clearly describes the decision for key decision points. Once that is done I'll add additional bullets to this test plan.

There should be a positive test for each of the "golden" C# scenarios in dotnet/csharplang#370:

  • (int, int) t = (x, y); // (int x, int y) on the right (TupleCreationWithInferredNames)
  • (int a, int b) t = (x, y); // (int x, int y) on the right (TupleCreationWithInferredNames)
  • var t = (x, y); // (int x, int y)
  • var t = (x, x); // (int, int)
  • var t = (n: x, x); // (int n, int x)
  • var t = (x, 5); // (int x, int)
  • var t = (x, x, y); // (int, int, int y)

There should be a positive test for corresponding "golden" VB scenarios: (TupleCreationWithInferredNames, TupleCreationWithInferredNames2)

  • Dim t As (Integer, Integer) = (x, y) ' (x As Integer, y As Integer) on the right
  • Dim t As (a As Integer, b As Integer) = (x, y) ' (x As Integer, y As Integer) on the right
  • Dim t = (x, y) ' (x As Integer, y As Integer)
  • Dim t = (x, x) ' (Integer, Integer)
  • Dim t = (n := x, x) ' (n As Integer, x As Integer)
  • Dim t = (x, 5) ' (x As Integer, Integer)
  • Dim t = (x, x, y) ' (Integer, Integer, y As Integer)

Test language version:

  • We should not infer tuple names in C# 7.0
    • or VB 15.0. (MissingMemberAccessWithVB15)
  • We should infer tuple names in C# 7.1
    • and VB 15.3. (TupleCreationWithInferredNames, TupleCreationWithInferredNames2)
  • We identified a breaking change for this feature. Write a program that displays different behavior depending on language version.
  • Add a note to the compiler breaking changes document for the language change's effect on existing programs.
  • Ensure the "default" language version is C# 7.0, and the "latest" is C# 7.1. These tests may already exist in master. (LanguageVersion_MapSpecifiedToEffectiveVersion)
  • Similarly ensure "default" and "latest" versions for VB. (LanguageVersion_MapSpecifiedToEffectiveVersion)

Tests specific to this feature:

  • Test to ensure correct (per spec) behavior when an inferred name would be of the form

    • Item1 (both in the correct and incorrect position) (tested on Item4 and Rest in TupleCreationWithInferredNamesWithCSharp7)
    • Item10 (both in the correct and incorrect position)
    • GetHashCode, Equals, ReferenceEquals
    • These same names are case-insensitive in VB.
  • Test to ensure no name inferred for a user-defined operator invocation

  • Test to ensure a name is inferred even if a user-defined conversion is applied after the expression

  • Test the interaction of "common type" with inferred names.

  • Test each of the syntactic constructs that cause a name to be inferred:

    • Identifer (local, parameter, field, property, event, enumeration constant)
    • expr.Identifier including this.Identifier and base.Identifier
    • expr?.Identifier
    • value in a property setter
    • A declaration expression with a simple designator (see below)
    • @_ as a plain identifier
    • @_ as a designator
    • Some other VB-specific contexts
  • Test that other syntactic constructs to not cause a name to be inferred:

    • tuple literal
    • expr.M() (except in VB)
    • ( Identifier )
    • checked ( Identifier ) and unchecked ( Identifier )
    • default(Type)
    • A _ discard expression in deconstruction.
    • A _ discard designator in deconstruction
  • Test that inferred names can come from the left-hand-side of a deconstruction

    • For a deconstruction-declaration like var (x, y) = (1, 2)
    • For a deconstruction-declaration like (var x, var y) = (1, 2)
    • For a deconstruction-declaration like (int x, int y) = (1, 2)
    • In nested scenarios (ValueTupleReturnWithInferredNamesWithCSharp7_1)
    • For a deconstruction assignment like (x, y) = (1, 2) (ValueTupleReturnIsEmittedIfUsed, ValueTupleReturnWithInferredNamesWithCSharp7_1)

Where names are inferred, test the behavior of APIs

  • GetDeclaredSymbol on the argument expression (probably should not declare the tuple element name)
  • GetTypeInfo
  • GetSpeculativeTypeInfo
  • Test the interaction of typeless tuples with inferred names is per spec. In this case inferred names are never used (there is no type to contain the inferred names).
  • Though it would be an error to use an inaccessible member in a tuple expression, the APIs should still show the name as being inferred based on the syntax.
  • Using a named constant (const declared member or local) should infer the name.
  • If the tuple is typeless, e.g. contains a method group, there should be no inferred names (because there is no type into which it could be inferred).

IDE tests (see also the IDE test plan); each for both languages

  • Is the inferred name colored appropriately at its use site?
  • Does completion after dotting off a tuple literal include inferred names?
  • Do inferred names show quick info when hovering on completion list items and uses?
  • Does selecting an inferred identifier also highlight other references to it?
  • Does extract method of a tuple literal include inferred names in the return type? (TestTupleWithInferredNames)
  • When using extract-method on an expression like x.y or y in a tuple literal, is it replaced by y: GeneratedMethod() to preserve the inferred element name?
  • Same as previous two questions for introduce-variable (or is it generate-local?) and/or generate-field instead of extract-method. (TupleWithInferredName_InferredNameBecomesExplicit)
  • Does inline-temporary-variable introduce a tuple element name lost by the inlining? E.g. changing (temp, 2) to (temp: expression, 2)? (ExplicitTupleNameAdded in C# and VB)
  • Does go-to-definition from a use of an inferred element name navigate to the element of the tuple literal? (manually verified)
  • Does find-all-references find other uses of the same inferred name?

Miscellaneous

@gafter gafter added Area-Compilers Feature - Tuples Tuples Test Test failures in roslyn-CI labels Apr 11, 2017
@gafter gafter added this to the 15.3 milestone Apr 11, 2017
@gafter gafter modified the milestones: 15.3, 15.5 Jun 27, 2017
@jcouv jcouv changed the title Test plan for "Infer tuple names" aka "tuple projection initializers" Test plan for "Infer tuple names" aka "tuple projection initializers" (7.1) Aug 1, 2017
@ufcpp
Copy link
Contributor

ufcpp commented Aug 23, 2017

Is this expected behavior?

using System;

static class Extensions
{
    public static void y(this (int, Action) t) => Console.WriteLine("extension y");
}

class Program
{
    static void Main()
    {
        int x = 1;
        Action y = () => Console.WriteLine("variable y");

        var t = (x, y);

        // "extension y" in VS 15.2
        // "variable y" with <LangVersion>7.1</LangVersion> in VS 15.3 (I know this is an expected breaking change)
        // error CS8306 with <LangVersion>7.0</LangVersion> in VS 15.3 (including 15.3.2. Is this expected?)
        t.y(); // CS8306 when LangVersion=7.0, Tuple element name 'y' is inferred. Please use language version 7.1 or greater to access an element by its inferred name.
    }
}

@jcouv
Copy link
Member

jcouv commented Aug 25, 2017

@ufcpp Yes, this is expected. When you upgrade the compiler, you get the new semantics, regardless of LangVersion. We don't try to emulate the old semantics when you set an old LangVersion.
Thanks

@gafter gafter removed their assignment Sep 13, 2017
@jcouv jcouv modified the milestones: 15.5, 15.later Oct 25, 2017
@gafter
Copy link
Member Author

gafter commented Nov 17, 2017

I'm closing this. @jcouv, do you want issues for additional possible tests?

@gafter gafter closed this as completed Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Tuples Tuples Test Test failures in roslyn-CI
Projects
None yet
Development

No branches or pull requests

3 participants