Skip to content

Intellisense for nullable types does not display the null postfix operator #3174

Closed

Description

@acoutts

Describe the bug
While working in a null safe dart project, if you start to type out a member from a class like fooClass., the intellisense popup does not display the null postfix operator:
Screen Shot 2021-03-03 at 7 13 09 AM
Notice the type is LiveForexQuote.

But hovering over the member, then the correct type (nullable) is shown:
Screen Shot 2021-03-03 at 7 13 30 AM

To Reproduce
Steps to reproduce the behavior:

  1. Create a nullable variable in a class
  2. Start typing to dereference that nullable class member
  3. Intellisense won't show the null postfix operator.

Expected behavior
Should show the null postfix operator like when you hover over it after typing it in.

Versions (please complete the following information):

Version: 1.53.0-exploration
Commit: 0c9e2dadd986d0bc085f1c5352245531eef65e84
Date: 2021-01-07T06:28:46.730Z (1 mo ago)
Electron: 11.1.0
Chrome: 87.0.4280.88
Node.js: 12.18.3
V8: 8.7.220.29-electron.0
OS: Darwin arm64 20.2.0
Dart code: 3.20.0

Activity

  1. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on Mar 3, 2021
  2. added this to the v3.21.0 milestone on Mar 3, 2021
  3. modified the milestones: v3.21.0, v3.22.0 on Mar 31, 2021
  4. DanTup commented on Apr 26, 2021

    @DanTup
    Member

    @bwilkerson this appears to be because DartType.getDisplayString calls that assume non-null here:

    https://github.com/dart-lang/sdk/blob/b10a592341bec4a00379d5c674a417b6b8c781a6/pkg/analysis_server/lib/src/protocol_server.dart#L57-L75

    If I change them to something like:

    final withNullability = element.returnType.element?.declaration?.library?.isNonNullableByDefault ?? false;
    return element.returnType.getDisplayString(withNullability: withNullability);

    It seems to handle this, but it leaves me with some questions:

    1. Which library should be used to determine whether to show it (here I'm using the library that declares the return type - I don't know if that's correct (I think hovers might be always using the source library?)
    2. If the library declaring the type works, could it be handled inside getDisplayString since it can access element?.declaration?.library?.isNonNullableByDefault directly?
  5. bwilkerson commented on Apr 26, 2021

    @bwilkerson

    Which library should be used to determine whether to show it ...

    Good question. I'm not sure what users want to see, but we've been using the principle that we should show the type that something has in the location at which it is referenced. If a top-level variable int? x; is declared in an opted in library, but is referenced from an opted out library, then we don't show the nullability marker. This matches what the spec says, and in the absence of evidence that that's wrong, it seems like a reasonable default.

  6. DanTup commented on Apr 27, 2021

    @DanTup
    Member
  7. DanTup commented on Apr 27, 2021

    @DanTup
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions