Skip to content

Commit 5bfbc6d

Browse files
authored
Fix internal error when missing measure attribute in an unsolved measure typar (#18234)
1 parent 72ab794 commit 5bfbc6d

18 files changed

+123
-0
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Fixed
22

33
* Fix Realsig+ generates nested closures with incorrect Generic ([Issue #17797](https://github.com/dotnet/fsharp/issues/17797), [PR #17877](https://github.com/dotnet/fsharp/pull/17877))
4+
* Fix internal error when missing measure attribute in an unsolved measure typar. ([Issue #7491](https://github.com/dotnet/fsharp/issues/7491), [PR #18234](https://github.com/dotnet/fsharp/pull/18234)==
45
* Set `Cancellable.token` from async computation ([Issue #18235](https://github.com/dotnet/fsharp/issues/18235), [PR #18238](https://github.com/dotnet/fsharp/pull/18238))
56

67
### Added

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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
open System.Runtime.CompilerServices
25+
type FooExt =
26+
[<Extension>]
27+
static member Bar(this: A<'u>, value: A<'u>) = this
28+
"""
29+
|> typecheck
30+
|> shouldFail
31+
|> withDiagnostics [
32+
(Error 3874, Line 9, Col 12, Line 9, Col 14, "Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute.")
33+
]
34+
35+
[<Fact>]
36+
let ``Expected unit-of-measure type parameter must be marked with the [<Measure>] attribute.`` () =
37+
Fsx """
38+
type A<[<Measure>]'u>(x : int<'u>) =
39+
member this.X = x
40+
41+
module M =
42+
type A<[<Measure>] 'u> with // Note the Measure attribute
43+
member this.Y = this.X
44+
45+
open System.Runtime.CompilerServices
46+
type FooExt =
47+
[<Extension>]
48+
static member Bar(this: A<'u>, value: A<'u>) = this
49+
"""
50+
|> typecheck
51+
|> shouldSucceed
52+

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)