Skip to content

Internal error when using custom attribute and omitting optional argument #8353

@chkn

Description

@chkn

There is an internal compiler error when you use a custom attribute and omit an optional argument tagged with System.Runtime.InteropServices.OptionalAttribute

Repro steps

module TestCase

open System
open System.Runtime.InteropServices

type FooAttribute(foo : string, bar : bool) =
    inherit Attribute()
    new([<Optional>] bar) = FooAttribute("", bar)

[<Foo>]
type Bar() = class end

Expected behavior

This should compile

Actual behavior

TestCase.fs(10,3): error FS0073: internal error: The type 'System.Boolean' may not be used as a custom attribute value

Known workarounds

Add a DefaultParameterValue attribute.

Related information

Provide any related information (optional):

  • Mac OS 10.15.1
  • Mono JIT compiler version 6.6.0.155 (2019-08/296a9afdb24 Thu Nov 14 06:12:25 EST 2019)
  • Microsoft (R) F# Compiler version 10.2.3 for F# 4.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-AttributesAttribute targets, AllowMultiple, CompiledName, custom attribute encodingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions