Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf728d9

Browse files
committed
allow inheriting from FSharpFunc
1 parent2d3a9bc commitdf728d9

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

‎src/fsharp/TastOps.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,11 @@ let helpEnsureTypeHasMetadata g ty =
794794
if isAnyTupleTy g tythen
795795
let(tupInfo,tupElemTys)= destAnyTupleTy g ty
796796
mkOuterCompiledTupleTy g(evalTupInfoIsStruct tupInfo) tupElemTys
797+
elif isFunTy g tythen
798+
let(a,b)= destFunTy g ty
799+
mkAppTy g.fastFunc_tcr[a; b]
797800
else ty
798-
799-
801+
800802
//---------------------------------------------------------------------------
801803
// Equivalence of types up to alpha-equivalence
802804
//---------------------------------------------------------------------------

‎src/fsharp/TypeChecker.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13270,6 +13270,7 @@ module MutRecBindingChecking =
1327013270
// Phase2B: typecheck the argument to an 'inherits' call and build the new object expr for the inherit-call
1327113271
| Phase2AInherit (synBaseTy, arg, baseValOpt, m) ->
1327213272
let baseTy, tpenv = TcType cenv NoNewTypars CheckCxs ItemOccurence.Use envInstance tpenv synBaseTy
13273+
let baseTy = baseTy |> helpEnsureTypeHasMetadata cenv.g
1327313274
let inheritsExpr, tpenv = TcNewExpr cenv envInstance tpenv baseTy (Some synBaseTy.Range) true arg m
1327413275
let envInstance = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envInstance | None -> envInstance
1327513276
let envNonRec = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envNonRec | None -> envNonRec
@@ -15073,6 +15074,9 @@ module EstablishTypeDefinitionCores =
1507315074
| SynTypeDefnSimpleRepr.Enum _ ->
1507415075
Some(cenv.g.system_Enum_typ)
1507515076

15077+
// Allow super type to be a function type but convert back to FSharpFunc<A,B> to make sure it has metadata
15078+
let super = super |> Option.map (helpEnsureTypeHasMetadata cenv.g)
15079+
1507615080
// Publish the super type
1507715081
tycon.TypeContents.tcaug_super <- super
1507815082

‎tests/fsharp/core/subtype/test.fsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,37 @@ module InferenceRegression4040C =
18731873
printfn"%A"(Foo.Test42)
18741874

18751875

1876+
moduleTestInheritFunc=
1877+
typeFoo()=
1878+
inherit FSharpFunc<int,int>()
1879+
override__.Invoke(a:int)= a+1
1880+
1881+
check"cnwcki1"((Foo()|> box|> unbox<int-> int>)5)6
1882+
1883+
moduleTestInheritFuncGeneric=
1884+
typeFoo<'T,'U>()=
1885+
inherit FSharpFunc<'T,'T>()
1886+
override__.Invoke(a:'T)= a
1887+
1888+
check"cnwcki2"((Foo<int,int>()|> box|> unbox<int-> int>)5)5
1889+
1890+
1891+
moduleTestInheritFunc2=
1892+
typeFoo()=
1893+
inherit OptimizedClosures.FSharpFunc<int,int,int>()
1894+
overridef.Invoke(a:int)=(fun u-> f.Invoke(a,u))
1895+
override__.Invoke(a:int,b:int)= a+ b+1
1896+
1897+
check"cnwcki3"((Foo()|> box|> unbox<int-> int-> int>)56)12
1898+
1899+
moduleTestInheritFunc3=
1900+
typeFoo()=
1901+
inherit OptimizedClosures.FSharpFunc<int,int,int,int>()
1902+
overridef.Invoke(t)=(fun u v-> f.Invoke(t,u,v))
1903+
override__.Invoke(a:int,b:int,c:int)= a+ b+ c+1
1904+
1905+
check"cnwcki4"((Foo()|> box|> unbox<int-> int-> int-> int>)567)19
1906+
18761907

18771908
#if TESTS_AS_APP
18781909
letRUN()=!failures

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp