dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.27k stars 1.58k forks source link

Invalid documentation for three FFI diagnostic codes #54416

Closed bwilkerson closed 11 months ago

bwilkerson commented 11 months ago

Three FFI related diagnostics now have documentation with example and fix code that produce unexpected diagnostics. Validation of the three has been disabled in ``, so they should be re-enabled as part of fixing this issue.

The output of the verification test (prior to disabling them) was

    FfiCode.NATIVE_FIELD_INVALID_TYPE
      Expected one error but found 4 (example 0):
        CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (36, 3) The name 'Int' isn't a type, so it can't be used as a type argument.
        CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE (41, 1) The non-nullable variable 'f' must be initialized.
        FfiCode.FFI_NATIVE_MUST_BE_EXTERNAL (41, 1) Native functions must be declared external.
        FfiCode.NATIVE_FIELD_INVALID_TYPE (41, 1) 'Array<InvalidType>' is an unsupported type for native fields. Native fields only support pointers or numeric and compound types.
      Expected no errors but found 3 (fixes 0):
        CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (38, 3) The name 'Int' isn't a type, so it can't be used as a type argument.
        CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE (43, 1) The non-nullable variable 'f' must be initialized.
        FfiCode.FFI_NATIVE_MUST_BE_EXTERNAL (43, 1) Native functions must be declared external.
    FfiCode.NATIVE_FIELD_MISSING_TYPE
      Expected one error but found 3 (example 0):
        CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE (34, 1) The non-nullable variable 'f' must be initialized.
        FfiCode.FFI_NATIVE_MUST_BE_EXTERNAL (34, 1) Native functions must be declared external.
        FfiCode.NATIVE_FIELD_MISSING_TYPE (34, 1) The native type of this field could not be inferred and must be specified in the annotation.
      Expected no errors but found 2 (fixes 0):
        CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE (41, 1) The non-nullable variable 'f' must be initialized.
        FfiCode.FFI_NATIVE_MUST_BE_EXTERNAL (41, 1) Native functions must be declared external.
    FfiCode.NATIVE_FIELD_NOT_STATIC
      Expected one error but found 3 (example 0):
        CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (40, 3) The name 'Int' isn't a type, so it can't be used as a type argument.
        FfiCode.NATIVE_FIELD_NOT_STATIC (62, 1) Native fields must be static.
        FfiCode.MUST_BE_A_SUBTYPE (62, 1) The type 'int' must be a subtype of 'InvalidType' for 'Native'.
      Expected no errors but found 2 (fixes 0):
        CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (40, 3) The name 'Int' isn't a type, so it can't be used as a type argument.
        FfiCode.MUST_BE_A_SUBTYPE (69, 1) The type 'int' must be a subtype of 'InvalidType' for 'Native'.
      Expected no errors but found 2 (fixes 1):
        CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (41, 3) The name 'Int' isn't a type, so it can't be used as a type argument.
        FfiCode.MUST_BE_A_SUBTYPE (61, 1) The type 'int' must be a subtype of 'InvalidType' for 'Native'.
      Expected no errors but found 3 (fixes 2):
        CompileTimeErrorCode.UNDEFINED_ANNOTATION (47, 6) Undefined name 'Int' used as an annotation.
        CompileTimeErrorCode.SUBTYPE_OF_BASE_IS_NOT_BASE_FINAL_OR_SEALED (26, 1) The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'Struct' is 'base'.
        FfiCode.MISSING_ANNOTATION_ON_STRUCT_FIELD (65, 3) Fields of type 'int' in a subclass of 'Struct' must have an annotation indicating the native type.
bwilkerson commented 11 months ago

@dcharkes @simolus3 @MaryaBelanger

dcharkes commented 11 months ago

Three FFI related diagnostics now have documentation with example and fix code that produce unexpected diagnostics. Validation of the three has been disabled in ``, so they should be re-enabled as part of fixing this issue.

@bwilkerson disabled in what?

CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT (36, 3) The name 'Int' isn't a type, so it can't be used as a type argument.

Are these validated against the mock sdk? In that case we need to add Int as AbiSpecificInteger there.

bwilkerson commented 11 months ago

disabled in what?

Sorry, I got interrupted and forgot that I hadn't finished.

They're disabled in analyzer/test/verify_diagnostics_test.dart. Or soon will be; the CL is out for review. I assumed I could get that CL landed and the bots green faster than fixing the code in the documentation.

Are these validated against the mock sdk?

Yes.

Adding that class will be part of the fix. The code also declared non-nullable variables and fields that aren't initialized, and that's also a problem. It was less clear to me what the initializers should look like.

dcharkes commented 11 months ago

@simolus3 Can you take a look at fixing this?

The mock SDK can be found in pkg/analyzer/lib/src/test_utilities/mock_sdk.dart. Please copy over the definition of Int there.

dcharkes commented 11 months ago

@bwilkerson which bots must we run on the CI to verify that we've got everything green?

I see these were red before your fix:

https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/analyzer-mac-release/25489/overview https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/analyzer-win-release/25290/overview

bwilkerson commented 11 months ago

If I'm remembering correctly, both of them were catching this error, so you ought to be able to run either one of them. I suspect that the mac bot will be faster.