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

Commit4adb2dd

Browse files
committed
Allow inheritance of types that have multiple interface instantiations
1 parent571841f commit4adb2dd

File tree

10 files changed

+29
-27
lines changed

10 files changed

+29
-27
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ chkUnionCaseDefaultAugmentation,"default augmentation of the union case"
291291
441,chkDuplicatePropertyWithSuffix,"Duplicate property. The property '%s' has the same name and signature as another property in this type once tuples, functions, units of measure and/or provided types are erased."
292292
442,chkDuplicateMethodInheritedType,"Duplicate method. The abstract method '%s' has the same name and signature as an abstract method in an inherited type."
293293
442,chkDuplicateMethodInheritedTypeWithSuffix,"Duplicate method. The abstract method '%s' has the same name and signature as an abstract method in an inherited type once tuples, functions, units of measure and/or provided types are erased."
294-
443,chkMultipleGenericInterfaceInstantiations,"This type implementsor inheritsthe same interface at different generic instantiations '%s' and '%s'. This is not permitted in this version of F#."
294+
443,chkMultipleGenericInterfaceInstantiations,"This type implements the same interface at different generic instantiations '%s' and '%s'. This is not permitted in this version of F#."
295295
444,chkValueWithDefaultValueMustHaveDefaultValue,"The type of a field using the 'DefaultValue' attribute must admit default initialization, i.e. have 'null' as a proper value or be a struct type whose fields all admit default initialization. You can use 'DefaultValue(false)' to disable this check"
296296
445,chkNoByrefInTypeAbbrev,"The type abbreviation contains byrefs. This is not permitted by F#."
297297
# -----------------------------------------------------------------------------

‎src/fsharp/NicePrint.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,7 @@ module private TastDefinitionPrinting =
13851385
GetImmediateInterfacesOfType g amap m ty|> List.map(fun ity-> wordL(if isInterfaceTy g tythen"inherit"else"interface")--- layoutType denv ity)
13861386

13871387
letprops=
1388-
//GetImmediateIntrinsicPropInfosOfType (None,ad) g amap m ty
1389-
GetIntrinsicPropInfosOfType infoReader(None,ad,AllowMultiIntfInstantiations.No) PreferOverrides m ty
1388+
GetIntrinsicPropInfosOfType infoReader(None,ad,AllowMultiIntfInstantiations.Yes) PreferOverrides m ty
13901389

13911390
letevents=
13921391
infoReader.GetEventInfosOfType(None,ad,m,ty)

‎src/fsharp/check.fs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ and CheckExprInContext (cenv:cenv) (env:env) expr (context:ByrefCallContext) =
495495
CheckInterfaceImpls cenv env basev iimpls;
496496
CheckTypePermitByrefs cenv m typ
497497
letinterfaces=
498-
[yield! AllSuperTypesOfType cenv.g cenv.amap m AllowMultiIntfInstantiations.Yes typ
498+
[//yield! AllSuperTypesOfType cenv.g cenv.amap m AllowMultiIntfInstantiations.Yes typ
499499
for(ty,_)in iimplsdo
500-
yield! AllSuperTypesOfType cenv.g cenv.amap m AllowMultiIntfInstantiations.Yes ty]
500+
yield ty]
501501
|> List.filter(isInterfaceTy cenv.g)
502502
CheckMultipleInterfaceInstantiations cenv interfaces m
503503

@@ -1379,7 +1379,9 @@ let CheckEntityDefn cenv env (tycon:Entity) =
13791379

13801380
if cenv.reportErrorsthen
13811381
ifnot tycon.IsTypeAbbrevthen
1382-
CheckMultipleInterfaceInstantiations cenv interfaces m
1382+
lettyp= generalizedTyconRef(mkLocalTyconRef tycon)
1383+
letimmediateInterfaces= GetImmediateInterfacesOfType cenv.g cenv.amap m typ
1384+
CheckMultipleInterfaceInstantiations cenv immediateInterfaces m
13831385

13841386
// Check struct fields. We check these late because we have to have first checked that the structs are
13851387
// free of cycles

‎src/fsharp/infos.fs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let ExistsInEntireHierarchyOfType f g amap m allowMultiIntfInst typ =
215215

216216
/// Search for one element where a function returns a 'Some' result, following interfaces
217217
letSearchEntireHierarchyOfType f g amap m typ=
218-
FoldHierarchyOfTypeAuxtrue AllowMultiIntfInstantiations.No
218+
FoldHierarchyOfTypeAuxtrue AllowMultiIntfInstantiations.Yes
219219
(fun ty acc->
220220
match accwith
221221
| None->if f tythen Some(ty)else None
@@ -243,11 +243,11 @@ let HasHeadType g tcref ty2 =
243243

244244
/// Check if a type exists somewhere in the hierarchy which has the same head type as the given type (note, the given type need not have a head type at all)
245245
letExistsSameHeadTypeInHierarchy g amap m typeToSearchFrom typeToLookFor=
246-
ExistsInEntireHierarchyOfType(HaveSameHeadType g typeToLookFor) g amap m AllowMultiIntfInstantiations.No typeToSearchFrom
246+
ExistsInEntireHierarchyOfType(HaveSameHeadType g typeToLookFor) g amap m AllowMultiIntfInstantiations.Yes typeToSearchFrom
247247

248248
/// Check if a type exists somewhere in the hierarchy which has the given head type.
249249
letExistsHeadTypeInEntireHierarchy g amap m typeToSearchFrom tcrefToLookFor=
250-
ExistsInEntireHierarchyOfType(HasHeadType g tcrefToLookFor) g amap m AllowMultiIntfInstantiations.No typeToSearchFrom
250+
ExistsInEntireHierarchyOfType(HasHeadType g tcrefToLookFor) g amap m AllowMultiIntfInstantiations.Yes typeToSearchFrom
251251

252252

253253
/// Read an Abstract IL type from metadata and convert to an F# type.
@@ -3145,13 +3145,13 @@ type InfoReader(g:TcGlobals, amap:Import.ImportMap) =
31453145
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicPropInfosOfType(optFilter,ad) g amap m typ:: acc) g amap m allowMultiIntfInst typ[]
31463146

31473147
letGetIntrinsicILFieldInfosUncached((optFilter,ad),m,typ)=
3148-
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicILFieldsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.No typ[]
3148+
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicILFieldsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.Yes typ[]
31493149

31503150
letGetIntrinsicEventInfosUncached((optFilter,ad),m,typ)=
3151-
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicEventsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.No typ[]
3151+
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicEventsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.Yes typ[]
31523152

31533153
letGetIntrinsicRecdOrClassFieldInfosUncached((optFilter,ad),m,typ)=
3154-
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicRecdOrClassFieldsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.No typ[]
3154+
FoldPrimaryHierarchyOfType(fun typ acc-> GetImmediateIntrinsicRecdOrClassFieldsOfType(optFilter,ad) m typ@ acc) g amap m AllowMultiIntfInstantiations.Yes typ[]
31553155

31563156
letGetEntireTypeHierachyUncached(allowMultiIntfInst,m,typ)=
31573157
FoldEntireHierarchyOfType(fun typ acc-> typ:: acc) g amap m allowMultiIntfInst typ[]
@@ -3182,7 +3182,7 @@ type InfoReader(g:TcGlobals, amap:Import.ImportMap) =
31823182
|_-> failwith"Unexpected multiple fields with the same name"// Because an explicit name (i.e., nm) was supplied, there will be only one element at most.
31833183
|_-> acc)
31843184
g amap m
3185-
AllowMultiIntfInstantiations.No
3185+
AllowMultiIntfInstantiations.Yes
31863186
typ
31873187
None
31883188

@@ -3524,12 +3524,12 @@ let TryFindIntrinsicNamedItemOfType (infoReader:InfoReader) (nm,ad) findFlag m t
35243524
/// -- getting the Dispose method when resolving the 'use' construct
35253525
/// -- getting the various methods used to desugar the computation expression syntax
35263526
letTryFindIntrinsicMethInfo infoReader m ad nm ty=
3527-
GetIntrinsicMethInfosOfType infoReader(Some nm,ad,AllowMultiIntfInstantiations.No) IgnoreOverrides m ty
3527+
GetIntrinsicMethInfosOfType infoReader(Some nm,ad,AllowMultiIntfInstantiations.Yes) IgnoreOverrides m ty
35283528

35293529
/// Try to find a particular named property on a type. Only used to ensure that local 'let' definitions and property names
35303530
/// are distinct, a somewhat adhoc check in tc.fs.
35313531
letTryFindPropInfo infoReader m ad nm ty=
3532-
GetIntrinsicPropInfosOfType infoReader(Some nm,ad,AllowMultiIntfInstantiations.No) IgnoreOverrides m ty
3532+
GetIntrinsicPropInfosOfType infoReader(Some nm,ad,AllowMultiIntfInstantiations.Yes) IgnoreOverrides m ty
35333533

35343534
//-------------------------------------------------------------------------
35353535
// Helpers related to delegates and events
@@ -3546,7 +3546,7 @@ let GetSigOfFunctionForDelegate (infoReader:InfoReader) delty m ad =
35463546
letg= infoReader.g
35473547
letamap= infoReader.amap
35483548
letinvokeMethInfo=
3549-
match GetIntrinsicMethInfosOfType infoReader(Some"Invoke",ad,AllowMultiIntfInstantiations.No) IgnoreOverrides m deltywith
3549+
match GetIntrinsicMethInfosOfType infoReader(Some"Invoke",ad,AllowMultiIntfInstantiations.Yes) IgnoreOverrides m deltywith
35503550
|[h]-> h
35513551
|[]-> error(Error(FSComp.SR.noInvokeMethodsFound(),m))
35523552
| h::_-> warning(InternalError(FSComp.SR.moreThanOneInvokeMethodFound(),m)); h

‎src/fsharp/nameres.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ let MakeNestedType (ncenv:NameResolver) (tinst:TType list) m (tcrefNested:TyconR
10291029
/// Get all the accessible nested types of an existing type.
10301030
letGetNestedTypesOfType(ad,ncenv:NameResolver,optFilter,staticResInfo,checkForGenerated,m)typ=
10311031
letg= ncenv.g
1032-
ncenv.InfoReader.GetPrimaryTypeHierachy(AllowMultiIntfInstantiations.No,m,typ)|> List.collect(fun typ->
1032+
ncenv.InfoReader.GetPrimaryTypeHierachy(AllowMultiIntfInstantiations.Yes,m,typ)|> List.collect(fun typ->
10331033
if isAppTy g typthen
10341034
lettcref,tinst= destAppTy g typ
10351035
lettycon= tcref.Deref
@@ -1371,7 +1371,7 @@ let ResolveObjectConstructor (ncenv:NameResolver) edenv m ad typ =
13711371
letIntrinsicPropInfosOfTypeInScope(infoReader:InfoReader)(optFilter,ad)findFlag m typ=
13721372
letg= infoReader.g
13731373
letamap= infoReader.amap
1374-
letpinfos= GetIntrinsicPropInfoSetsOfType infoReader(optFilter, ad, AllowMultiIntfInstantiations.No) findFlag m typ
1374+
letpinfos= GetIntrinsicPropInfoSetsOfType infoReader(optFilter, ad, AllowMultiIntfInstantiations.Yes) findFlag m typ
13751375
letpinfos= pinfos|> ExcludeHiddenOfPropInfos g amap m
13761376
pinfos
13771377

@@ -1399,7 +1399,7 @@ let ExtensionPropInfosOfTypeInScope (infoReader:InfoReader) (nenv: NameResolutio
13991399
letg= infoReader.g
14001400

14011401
letextMemsFromHierarchy=
1402-
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.No,m,typ)|> List.collect(fun typ->
1402+
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,typ)|> List.collect(fun typ->
14031403
if(isAppTy g typ)then
14041404
lettcref= tcrefOfAppTy g typ
14051405
letextMemInfos= nenv.eIndexedExtensionMembers.Find tcref
@@ -1461,7 +1461,7 @@ let SelectMethInfosFromExtMembers (infoReader:InfoReader) optFilter apparentTy m
14611461
letExtensionMethInfosOfTypeInScope(infoReader:InfoReader)(nenv:NameResolutionEnv)optFilter m typ=
14621462
letextMemsDangling= SelectMethInfosFromExtMembers infoReader optFilter typ m nenv.eUnindexedExtensionMembers
14631463
letextMemsFromHierarchy=
1464-
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.No,m,typ)|> List.collect(fun typ->
1464+
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,typ)|> List.collect(fun typ->
14651465
letg= infoReader.g
14661466
if(isAppTy g typ)then
14671467
lettcref= tcrefOfAppTy g typ
@@ -1472,7 +1472,7 @@ let ExtensionMethInfosOfTypeInScope (infoReader:InfoReader) (nenv: NameResolutio
14721472

14731473
/// Get all the available methods of a type (both intrinsic and extension)
14741474
letAllMethInfosOfTypeInScope infoReader nenv(optFilter,ad)findFlag m typ=
1475-
IntrinsicMethInfosOfType infoReader(optFilter,ad,AllowMultiIntfInstantiations.No) findFlag m typ
1475+
IntrinsicMethInfosOfType infoReader(optFilter,ad,AllowMultiIntfInstantiations.Yes) findFlag m typ
14761476
@ ExtensionMethInfosOfTypeInScope infoReader nenv optFilter m typ
14771477

14781478

‎src/fsharp/tastops.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ type TyconRefMultiMap<'T>(contents: TyconRefMap<'T list>) =
12391239
memberm.Find v=if contents.ContainsKey vthen contents.[v]else[]
12401240
memberm.Add(v,x)= TyconRefMultiMap<'T>(contents.Add v(x:: m.Find v))
12411241
static memberEmpty= TyconRefMultiMap<'T>(TyconRefMap<_>.Empty)
1242+
static memberOfList vs=(vs, TyconRefMultiMap<'T>.Empty)||> List.foldBack(fun(x,y)acc-> acc.Add(x, y))
12421243

12431244

12441245
//--------------------------------------------------------------------------

‎src/fsharp/tastops.fsi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ type TyconRefMultiMap<'T> =
278278
memberFind:TyconRef->'T list
279279
memberAdd:TyconRef* 'T-> TyconRefMultiMap<'T>
280280
static member Empty: TyconRefMultiMap<'T>
281+
static member OfList:(TyconRef* 'T) list-> TyconRefMultiMap<'T>
281282

282283

283284
//-------------------------------------------------------------------------

‎src/fsharp/tc.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ let IsSecurityAttribute g amap (casmap : Dictionary<Stamp,bool>) (Attrib(tcref,_
118118
if casmap.ContainsKey(tcs) then
119119
casmap.[tcs]
120120
else
121-
let exists = ExistsInEntireHierarchyOfType (fun t -> typeEquiv g t (mkAppTy attr.TyconRef [])) g amap m AllowMultiIntfInstantiations.No (mkAppTy tcref [])
121+
let exists = ExistsInEntireHierarchyOfType (fun t -> typeEquiv g t (mkAppTy attr.TyconRef [])) g amap m AllowMultiIntfInstantiations.Yes (mkAppTy tcref [])
122122
casmap.[tcs] <- exists
123123
exists
124124
| _ -> false
@@ -5603,7 +5603,7 @@ and TcIndexerThen cenv env overallTy mWholeExpr mDot tpenv wholeExpr e1 indexArg
56035603
cenv.g
56045604
cenv.amap
56055605
mWholeExpr
5606-
AllowMultiIntfInstantiations.No
5606+
AllowMultiIntfInstantiations.Yes
56075607
e1ty
56085608
None
56095609
| _ -> Some "GetSlice"
@@ -14111,7 +14111,7 @@ module EstablishTypeDefinitionCores = begin
1411114111
// validate ConditionalAttribute, should it be applied (it's only valid on a type if the type is an attribute type)
1411214112
match attrs |> List.tryFind (IsMatchingFSharpAttribute cenv.g cenv.g.attrib_ConditionalAttribute) with
1411314113
| Some _ ->
14114-
if not(ExistsInEntireHierarchyOfType (fun t -> typeEquiv cenv.g t (mkAppTy cenv.g.tcref_System_Attribute [])) cenv.g cenv.amap m AllowMultiIntfInstantiations.No thisTy) then
14114+
if not(ExistsInEntireHierarchyOfType (fun t -> typeEquiv cenv.g t (mkAppTy cenv.g.tcref_System_Attribute [])) cenv.g cenv.amap m AllowMultiIntfInstantiations.Yes thisTy) then
1411514115
errorR(Error(FSComp.SR.tcConditionalAttributeUsage(),m))
1411614116
| _ -> ()
1411714117

‎src/fsharp/typrelns.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ module DispatchSlotChecking =
12811281
// This contains the list of required members and the list of available members
12821282
[for(_,reqdTy,reqdTyRange,impliedTys)in reqdTyInfosdo
12831283

1284-
// Build atable of the implied interface types, for quicker lookup
1284+
// Build aset of the implied interface types, for quicker lookup, by nominal type
12851285
letisImpliedInterfaceTable=
12861286
impliedTys
12871287
|> List.filter(isInterfaceTy g)
@@ -1718,7 +1718,7 @@ type CalledMeth<'T>
17181718
letreturnedObjTy=if minfo.IsConstructorthen minfo.EnclosingTypeelse methodRetTy
17191719
unassignedNamedItem|> List.splitChoose(fun(CallerNamedArg(id,e)asarg)->
17201720
letnm= id.idText
1721-
letpinfos= GetIntrinsicPropInfoSetsOfType infoReader(Some(nm),ad,AllowMultiIntfInstantiations.No) IgnoreOverrides id.idRange returnedObjTy
1721+
letpinfos= GetIntrinsicPropInfoSetsOfType infoReader(Some(nm),ad,AllowMultiIntfInstantiations.Yes) IgnoreOverrides id.idRange returnedObjTy
17221722
letpinfos= pinfos|> ExcludeHiddenOfPropInfos g infoReader.amap m
17231723
match pinfoswith
17241724
|[pinfo]when pinfo.HasSetter&&not pinfo.IsIndexer->

‎tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/InterfaceTypes/E_ConsumeMultipleInterfaceFromCS.fs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// #Conformance #ObjectOrientedTypes #InterfacesAndImplementations #ReqNOMT
2-
// <Expects id="FS0443" status="error" span="(19,6-23,8)">This type implements or inherits the same interface at different generic instantiations 'I_002\<string\>' and 'I_002\<char\>'\. This is not permitted in this version of F#\.</Expects>
32
#light
43

54
let mutableres=true

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp