Skip to content

Commit d69c8ac

Browse files
add FS0067 compiler message (#48442)
1 parent 6b69d43 commit d69c8ac

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: "Learn more about: FS0067: This type test or downcast will always hold"
3+
title: "Compiler error FS0067"
4+
ms.date: 9/10/2025
5+
f1_keywords:
6+
- "FS0067"
7+
helpviewer_keywords:
8+
- "FS0067"
9+
---
10+
11+
# FS0067: This type test or downcast will always hold
12+
13+
This message is given when attempting to perform a type test ([:?](../match-expressions.md)) or downcast ([:?>](../casting-and-conversions.md#downcasting)) that will always succeed based on the types involved, making the operation unnecessary.
14+
15+
Redundant Type test:
16+
17+
[!code-fsharp[FS0067-redundant-type-test](~/samples/snippets/fsharp/compiler-messages/fs0067.fsx#L2-L8)]
18+
19+
Redundant Downcast:
20+
21+
[!code-fsharp[FS0067-redundant-downcast](~/samples/snippets/fsharp/compiler-messages/fs0067.fsx#L11-L18)]
22+
23+
The two examples above cause the compiler to display the following message:
24+
25+
```text
26+
FS0067: This type test or downcast will always hold
27+
```
28+
29+
The use of `:?` and `:?>` operators is preferable when working with:
30+
31+
- Base classes when the runtime type might differ.
32+
- Values of type `obj` or interfaces types.

docs/fsharp/language-reference/compiler-messages/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
href: ./fs0037.md
2020
- name: FS0052 - Defensive copy
2121
href: ./fs0052.md
22+
- name: FS0067 - This type test or downcast will always hold
23+
href: ./fs0067.md
2224
- name: FS0703 - Expected type parameter, not unit-of-measure parameter
2325
href: ./fs0703.md
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(* Redundant Type test *)
2+
type Dog() =
3+
member this.Bark() = printfn "Woof!"
4+
5+
let dog = Dog()
6+
7+
if dog :? Dog then
8+
dog.Bark()
9+
10+
(* Redundant Downcast *)
11+
type Cat(name: string) =
12+
member this.Name = name
13+
14+
let cat = Cat("Kitten")
15+
16+
let sameCat = cat :?> Cat
17+
18+
printfn "It's still a %s" sameCat.Name

0 commit comments

Comments
 (0)