dotnet / dotnet/fsharp

Wrong confusing warning FS1189 when using SRTP with active patterns

Open
#7,797 2 comments 1 reaction 1 assignee Claimed by @edgarfgp View on GitHub
Area-Compiler-Syntax Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

This is fine:

```f#
let inline IsEqual< ^t when ^t: equality> (x: ^t) =
x = x
```

But this is not:

```f#
let inline (|IsEqual|IsNonEqual|)< ^t when ^t : equality> (x: ^t) =
if x = x then -> IsEqual
else IsNonEqual
```

![image](https://user-images.githubusercontent.com/16015770/67988295-d775e100-fc2f-11e9-9fea-2773913b0534.png)

Note: the code above does not require an explicit SRTP, but I just wanted to keep it simple. The actual example came from my comment here: https://github.com/fsharp/fslang-suggestions/issues/661#issuecomment-548542518

It can be seen with any SRTP type constraint, the full warning being:

> warning FS1189: Remove spaces between the type name and type parameter, e.g. "type C<'T>", not type "C <'T>". Type parameters must be placed directly adjacent to the type name.

**Known workarounds**

Ignore the warning (but that will ignore it for the whole file).

**Other info**

It has been reported before, but writing `<^t` instead of `< ^t` will yield a syntax error. Though I doubt that is the space the compiler complains about.

Also: the actual warning doesn't seem tailored for SRTP, it shows examples for normal type constraints, which can be confusing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.