Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5362,11 +5362,15 @@ and GenBindRhs cenv cgbuf eenv sp (vspec:Val) e =
| Expr.TyLambda _ | Expr.Lambda _ ->
let isLocalTypeFunc = IsNamedLocalTypeFuncVal cenv.g vspec e

match e, isLocalTypeFunc with
| Expr.TyLambda(_, tyargs, body, _, _), true when
match e with
| Expr.TyLambda(_, tyargs, body, _, ttype) when
(
tyargs |> List.forall (fun tp -> tp.IsErased) &&
(match StorageForVal vspec.Range vspec eenv with Local _ -> true | _ -> false)
(match StorageForVal vspec.Range vspec eenv with Local _ -> true | _ -> false) &&
(isLocalTypeFunc ||
(match ttype with
TType_var(typar) -> match typar.Solution with Some(TType_app(t,_))-> t.IsStructOrEnumTycon | _ -> false
| _ -> false))
) ->
// type lambda with erased type arguments that is stored as local variable (not method or property)- inline body
GenExpr cenv cgbuf eenv sp body Continue
Expand Down
8 changes: 8 additions & 0 deletions tests/fsharp/regression/struct-measure-bug-1/test.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type AStruct<[<Measure>]'u> =
struct
end

[<EntryPoint>]
let main argv =
let x = AStruct() // This doesn't work
0
8 changes: 8 additions & 0 deletions tests/fsharp/tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,14 @@ module RegressionTests =
[<Test >]
let ``struct-tuple-bug-1-FSI_BASIC`` () = singleTestBuildAndRun "regression/struct-tuple-bug-1" FSI_BASIC

[<Test>]
let ``struct-measure-bug-1`` () =
let cfg = testConfig "regression/struct-measure-bug-1"

fsc cfg "%s --optimize- -o:test.exe -g" cfg.fsc_flags ["test.fs"]

peverify cfg "test.exe"

#if !FSHARP_SUITE_DRIVES_CORECLR_TESTS
module OptimizationTests =

Expand Down