Fsharp: Inline comment within list causes incorrect compiler error

Created on 21 Jun 2019  路  5Comments  路  Source: dotnet/fsharp

Repro steps

let bug =
    [
        1
        (*comment*) 2
    ]

Expected behavior

This should create a list of two elements: [1; 2]

Actual behavior

Compiler interprets the inline comment as an attempted function application: "This value is not a function and cannot be applied."

Known workarounds

Add semicolon to end of line:

let bugFix =
    [
        1;
        (*comment*) 2
    ]

Related information

  • Windows 7 x64
  • .NET Framework 4.7.2
  • Visual Studio 16.1.3
Area-Compiler Resolution-By Design bug

All 5 comments

Good catch. This shouldn't be the behavior.

It's not due to the comment. Comments are erased during lex-filter stage (aka indentation or offside rule checking) where 1 and 2 must have the same indentation and they are not, so it works according to the spec.

I see. You're right that I get the same behavior without the comment, so I guess this is working as intended.

That's why we need to improve that error message badly... Even more than https://github.com/dotnet/fsharp/pull/6820 does

Yes, in case the problem occurs on a linebreak, it should explain that it can be due to a problem with indentation alignment 鉁煣犫湪

Was this page helpful?
0 / 5 - 0 ratings