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 "file types" #60819

Closed
68 of 83 tasks
RikkiGibson opened this issue Apr 18, 2022 · 3 comments
Closed
68 of 83 tasks

Test plan for "file types" #60819

RikkiGibson opened this issue Apr 18, 2022 · 3 comments

Comments

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Apr 18, 2022

Proposal: dotnet/csharplang#6011
Spec: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/file-local-types.md

Compiler

  • type named @file exists
  • type in nested namespace can hide file-type: file class C { } namespace N { class C { } class D { ... use unqualified "C" (ie. type N.C) ... } }
  • SyntaxNormalizer
  • file type "var" (or some other contextual keyword) declared
  • SPEC: disallowed in global using (see GlobalUsingStatic_01)
  • add modifier to compiler test plan
  • file-interface can be implemented (implicitly or explicitly), but not when signature leaks file-type (see InterfaceImplementation_*)
  • type named "file" disallowed (should be error)
  • top-level local function named "file" exists
  • file-type allowed in attribute type
  • spec
  • modifier only allowed in new LangVer (see LangVersion)
  • modifier only allowed on top-level types (see Nested_*, AccessThroughType_*)
  • modifier can only be specified once (see DuplicateModifiers_01)
  • modifier allowed on various kinds of types:
    • class
    • struct,
    • record, record struct(seePrimaryConstructor_01`)
    • interface (see InterfaceImplementation_02)
    • enum (see FileEnum_*)
    • delegate
  • access modifiers disallowed on file-types (see AccessModifiers_01)
  • duplicate file-types are disallowed
  • file-type can be static (see StaticFileClass)
  • file-type can be generic (see Generic_01)
  • partial file-types in same file are the same type (see Duplication_04)
  • partial file-types in different files are different types (see Duplication_05)
  • file-type only allowed in base type of file-types (top-level or nested in generic or tuple) (see BaseClause_*)
    • generic base type instantiated with file-type?
    • using an alias as base (see Alias_01)
  • file-type can have a base type or implement an interface (see Nested_06, BaseClause_02)
  • file-type only allowed in signatures within file-types (see SignatureUsage_*, PrimaryConstructor_01)
    • positive cases?
  • file-type as type constraint
    • on method (see Constraints_01)
    • on various other declarations: types, ...
  • file-type can be accessed with unqualified or qualified name (see AccessThroughNamespace_*)
  • file-type can be accessed via using, static using, but not global using (see AccessThroughGlobalUsing_*, GlobalUsingStatic_01, UsingStatic_*)
  • file-type can be accessed from top-level statements (see TopLevelStatements)
  • file-types can introduce extension methods (see ExtensionMethod_*)
  • file-types of same name can be declared in various nested namespaces (usual scoping rules apply)
  • types can be shadowed and there's no way to access shadowed types
  • file-type cannot be accessed from another file
    • file class C { } class Program { class C { } ... method with usage of inner class C ... }
    • file class C { } class Program<C>{ ... method with usage of type parameter C ... }
    • file class C { } class Program<C, T> where T : C { }
    • file record C(C x);
    • file class C<T> where T : C { }
  • file-type can be used in various locations that allow types:
    • locals,
    • constraints (methods, types, delegates),
    • interface (see BaseClause_02)
    • attributes (see FileEnum_02)
    • typeof,
    • nameof
    • alias (see Alias_01)
    • base type (file class Outer { class Inner : Outer { } }
    • file class Outer { class Inner : Base<Outer> { } }),
    • lambdas (see Lambda_01)
    • local functions (see LocalFunction_01)
    • anonymous types
    • cref (see Cref_*)
    • ...
  • SymbolDisplay shows unspeakable name (see SymbolDisplay)
  • Scripting (see Script_01)
  • EE (done in PR File types EE support #62812)
  • Semantic model (LookupSymbols, GetSymbolInfo) (see SemanticModel_*)
  • Speculation (see Speculation_01)
  • Base reference in partial error scenario File types binding #60977 (comment)
  • PDB verification (no changes in initial design)
  • public API: should we have bool INamedTypeSymbol.IsFile? Possibly SyntaxTree? INamedTypeSymbol.AssociatedSyntaxTree?
  • public API: should we have public SymbolDisplayOptions to show the associated file of a named type? e.g. NS.MyClass@MyFile.
  • GetTypeByMetadataName (see GetTypeByMetadataName_*)
  • Confirm whether we should have SymbolDisplayCompilerInternalOptions.IncludeContainingFileForFileTypes
  • IsFile should be false on a nested type with file modifier

Language

  • LDM question: allow file types in signatures of explicit interface implementations within non-file types? e.g. class C { void SomeInterface.M(FileType ft) { } } File types binding #60977 (comment) (answer: no)

Productivity

  • completion for file (done in PR File types IDE changes #62215)
  • colorization/classification for file (verified manually)
  • formatting/spacing for file (verified manually)
  • nav bar disambiguation when regular type and file-type with same name are in the current file (verified manually)
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 18, 2022
@RikkiGibson RikkiGibson changed the title Test plan for "file-scoped types" Test plan for "file types" Apr 18, 2022
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 18, 2022
@jcouv jcouv modified the milestones: Compiler.Next, C# 11.0 Apr 18, 2022
@jcouv jcouv added this to Active/Investigating in Compiler: Julien's umbrellas Apr 28, 2022
@jcouv jcouv moved this from Active/Investigating to Language in Compiler: Julien's umbrellas Apr 28, 2022
@tmat
Copy link
Member

tmat commented Jun 3, 2022

We should also consider scope of the type declaration in interactive submissions.

Defining the type in one submission and accessing it in another one should probably work:

> file class C {}
> new C()
> file class C {} // should hide original definition of C

However, each submission has a different file name (e.g. Submission#0, Submission#1, etc.).

If a file type is defined in a .csx file that is then loaded to another one the type should not be accessible:

C.csx:

file class C {}
> #load "C.csx"
> new C(); // error

@jcouv
Copy link
Member

jcouv commented Oct 7, 2022

Spotted one spec gap (Rikki will update spec). Otherwise the test coverage is pretty comprehensive. Only a couple minor bullets were not checked. I'll go ahead and close the test plan.

@RikkiGibson
Copy link
Contributor Author

A few missing tests were noted in recent discussion with @AlekseyTs.

  • What happens when we try to use a file-type by name in -main:<type>. Test with both its source name and metadata name.
  • What happens when partial file class is combined with top-level-statements. SharpLab.
  • What happens when partial file class and partial class are used together in the same file. (related to the previous point). SharpLab
    • I don't think we're sure what should happen here. It feels like a 'file class' never has the same name as a non-file class, in a sense, so maybe it doesn't make sense to group them, and we should require repeating the file modifier in all the partial declarations of a file type. May need to confirm with LDM.

@RikkiGibson RikkiGibson reopened this Mar 23, 2023
@RikkiGibson RikkiGibson modified the milestones: 17.4, 17.6 Mar 23, 2023
@jcouv jcouv assigned RikkiGibson and unassigned jcouv Mar 31, 2023
@jcouv jcouv modified the milestones: 17.6, 17.7 Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants