diff --git a/src/fsharp/Optimizer.fs b/src/fsharp/Optimizer.fs index f306840fa8..1130f7d186 100644 --- a/src/fsharp/Optimizer.fs +++ b/src/fsharp/Optimizer.fs @@ -2749,7 +2749,14 @@ and OptimizeLambdas (vspec: Val option) cenv env topValInfo e ety = let valu = match baseValOpt with | None -> CurriedLambdaValue (lambdaId,arities,bsize,expr',ety) - | _ -> UnknownValue + | Some baseVal -> + let fvs = freeInExpr CollectLocals body' + if fvs.UsesMethodLocalConstructs || fvs.FreeLocals.Contains baseVal then + UnknownValue + else + let expr2 = mkMemberLambdas m tps ctorThisValOpt None vsl (body',bodyty) + CurriedLambdaValue (lambdaId,arities,bsize,expr2,ety) + expr', { TotalSize=bsize + (if isTopLevel then methodDefnTotalSize else closureTotalSize); (* estimate size of new syntactic closure - expensive, in contrast to a method *) FunctionSize=1; diff --git a/tests/fsharp/core/subtype/test.fsx b/tests/fsharp/core/subtype/test.fsx index 321c202c96..052230b699 100644 --- a/tests/fsharp/core/subtype/test.fsx +++ b/tests/fsharp/core/subtype/test.fsx @@ -1484,9 +1484,9 @@ module TestTwoConversionsOK = // asserted to be equal. // //This rule is a deliberate artificial limitation to reduce the complexity -// of type inference in the common case, at the cost of making “inline” code +// of type inference in the common case, at the cost of making “inline” code // less generic. However, the rule should not apply to op_Explicit and op_Implicit constraints. These are special constraint names, known to the language, and we already have special rules around these operators to ensure that the return type -// is effectively considered to be part of the “name” of the constraint +// is effectively considered to be part of the “name” of the constraint // (i.t. op_Explicit --> int64 is effectively a different constraint to op_Explicit --> int32). // //So the solution is thus to not apply the rule for these constraints. @@ -1696,6 +1696,24 @@ module RecordPropertyConstraintTests = check "ckjwnewk" (f8()) (System.TimeSpan.FromSeconds 2.0) // after mutation check "ckjwnewk" (f10()) "Gary" +// See https://github.com/Microsoft/visualfsharp/issues/740 - inlining on subtypes was not allowed +module InliningOnSubTypes1 = + type A() = + static member inline dosomething() = () + + type B() = + inherit A() + member inline this.SomethingElse a = a + 10 + member inline this.SomethingElse2 a b = a + b + 10 + + let f () = + let b = B() + let x1 = b.SomethingElse 3 + let x2 = b.SomethingElse2 3 4 + (x1, x2) + do check "clkewlijwlkw" (f()) (13, 17) + + // See https://github.com/Microsoft/visualfsharp/issues/238 module GenericPropertyConstraintSolvedByRecord = @@ -1711,4 +1729,4 @@ let aa = do (stdout.WriteLine "Test Passed"; System.IO.File.WriteAllText("test.ok","ok"); - exit 0) \ No newline at end of file + exit 0)