Skip to content

Commit

Permalink
Combining struct field with units of measure will result managed type…
Browse files Browse the repository at this point in the history
… instead of unmanaged type

fixes dotnet#276
closes dotnet#289

commit 843272178d4369d1fc028ea46956fb669242c212
Author: latkin <latkin@microsoft.com>
Date:   Tue Mar 10 11:19:54 2015 -0700

    Add test covering original bug

commit 4d194c4
Author: andrewjkennedy <akenn@microsoft.com>
Date:   Mon Mar 2 13:13:27 2015 +0000

    Fix for dotnet#276:
    Combining struct field with units of measure will result managed type instead of unmanaged type

    (Regression test to follow)
  • Loading branch information
andrewjkennedy authored and latkin committed Mar 10, 2015
1 parent 9e13bdd commit 220c17d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/fsharp/csolve.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,8 +1740,7 @@ and SolveTypIsUnmanaged (csenv:ConstraintSolverEnv) ndeep m2 trace ty =
if isTyparTy g ty then
AddConstraint csenv ndeep m2 trace (destTyparTy g ty) (TyparConstraint.IsUnmanaged(m))
else
let underlyingTy = stripTyEqnsAndMeasureEqns g ty
if isUnmanagedTy g underlyingTy then
if isUnmanagedTy g ty then
CompleteD
else
ErrorD (ConstraintSolverError(FSComp.SR.csGenericConstructRequiresUnmanagedType(NicePrint.minimalStringOfType denv ty),m,m2))
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/tastops.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ let isStructTy g ty =
// - Any non-generic user-defined struct-type that contains fields of unmanaged-types only.
// [Note: Constructed types and type-parameters are never unmanaged-types. end note]
let rec isUnmanagedTy g ty =
let ty = stripTyEqnsAndMeasureEqns g ty
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
let isEq tcref2 = tyconRefEq g tcref tcref2
Expand Down
9 changes: 9 additions & 0 deletions tests/fsharp/typecheck/sigs/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ call %~d0%~p0..\..\..\config.bat
call ..\..\single-neg-test.bat neg91
@if ERRORLEVEL 1 goto Error

"%FSC%" %fsc_flags% --target:exe -o:pos20.exe pos20.fs
@if ERRORLEVEL 1 goto Error

"%PEVERIFY%" pos20.exe
@if ERRORLEVEL 1 goto Error

pos20.exe
@if ERRORLEVEL 1 goto Error

"%FSC%" %fsc_flags% --target:exe -o:pos19.exe pos19.fs
@if ERRORLEVEL 1 goto Error

Expand Down
16 changes: 16 additions & 0 deletions tests/fsharp/typecheck/sigs/pos20.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// test covering https://github.com/Microsoft/visualfsharp/issues/276

open FSharp.Data.UnitSystems.SI.UnitSymbols

[<Struct>]
type S1 =
val X: int

[<Struct>]
type S2 =
val X: int<m>

let f (x : 'T when 'T: unmanaged and 'T: struct) = printfn "%A" x

f (S1())
f (S2()) // previously had error FS0001: A generic construct requires that the type 'S2' is an unmanaged type

0 comments on commit 220c17d

Please sign in to comment.