Skip to content

Commit 80ef337

Browse files
committed
Fix internal error when missing Measure attribute in a unsolved measure typar
1 parent b204f87 commit 80ef337

17 files changed

+112
-0
lines changed

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,5 +1789,6 @@ featureUseTypeSubsumptionCache,"Use type conversion cache during compilation"
17891789
3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern."
17901790
featureDontWarnOnUppercaseIdentifiersInBindingPatterns,"Don't warn on uppercase identifiers in binding patterns"
17911791
3873,chkDeprecatePlacesWhereSeqCanBeOmitted,"This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}'"
1792+
3874,tcExpectedTypeParamMarkedWithUnitOfMeasureAttribute,"Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute."
17921793
featureDeprecatePlacesWhereSeqCanBeOmitted,"Deprecate places where 'seq' can be omitted"
17931794
featureSupportValueOptionsAsOptionalParameters,"Support ValueOption as valid type for optional member parameters"

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ and remapMeasureAux tyenv unt =
243243
| Some tpTy ->
244244
match tpTy with
245245
| TType_measure unt -> unt
246+
| TType_var(typar= typar) when tp.Kind = TyparKind.Measure ->
247+
// This is a measure typar that is not yet solved, so we can't remap it
248+
error(Error(FSComp.SR.tcExpectedTypeParamMarkedWithUnitOfMeasureAttribute(), typar.Range))
246249
| _ -> failwith "remapMeasureAux: incorrect kinds"
247250
| None -> unt
248251
| Some (TType_measure unt) -> remapMeasureAux tyenv unt

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ru.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.tr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
module ErrorMessages.UnitOfMeasureTests
4+
5+
open Xunit
6+
open FSharp.Test.Compiler
7+
8+
[<Fact>]
9+
let ``Error - Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute.`` () =
10+
Fsx """
11+
type A<[<Measure>]'u>(x : int<'u>) =
12+
member this.X = x
13+
14+
type B<'u>(x: 'u) =
15+
member this.X = x
16+
17+
module M =
18+
type A<'u> with // Note the missing Measure attribute
19+
member this.Y = this.X
20+
21+
type B<'u> with
22+
member this.Y = this.X
23+
"""
24+
|> typecheck
25+
|> shouldFail
26+
|> withDiagnostics [
27+
(Error 3874, Line 9, Col 12, Line 9, Col 14, "Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute.")
28+
]
29+
30+
[<Fact>]
31+
let ``Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute.`` () =
32+
Fsx """
33+
type A<[<Measure>]'u>(x : int<'u>) =
34+
member this.X = x
35+
36+
module M =
37+
type A<[<Measure>] 'u> with // Note the Measure attribute
38+
member this.Y = this.X
39+
"""
40+
|> typecheck
41+
|> shouldSucceed
42+

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
<Compile Include="ErrorMessages\InterfaceImplInAugmentationsTests.fs" />
219219
<Compile Include="ErrorMessages\ExtendedDiagnosticDataTests.fs" />
220220
<Compile Include="ErrorMessages\ActivePatternArgCountMismatchTest.fs" />
221+
<Compile Include="ErrorMessages\UnitOfMeasureTests.fs" />
221222
<Compile Include="Language\IndexerSetterParamArray.fs" />
222223
<Compile Include="Language\MultiDimensionalArrayTests.fs" />
223224
<Compile Include="Language\RegressionTests.fs" />

0 commit comments

Comments
 (0)