Skip to content

Commit 196f300

Browse files
KevinRansombaronfel
authored andcommitted
more tests
1 parent 675e056 commit 196f300

1 file changed

Lines changed: 72 additions & 41 deletions

File tree

src/fsharp/PostInferenceChecks.fs

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -707,49 +707,80 @@ let compareTypesWithRegardToTypeVariablesAndMeasures g amap m typ1 typ2 =
707707
else
708708
NotEqual
709709

710+
//let CheckMultipleInterfaceInstantiations cenv (typ:TType) (interfaces:TType list) isObjectExpression m =
711+
// let keyf ty = assert isAppTy cenv.g ty; (tcrefOfAppTy cenv.g ty).Stamp
712+
// if not(cenv.g.langVersion.SupportsFeature LanguageFeature.InterfacesWithMultipleGenericInstantiation) then
713+
// let table = interfaces |> MultiMap.initBy keyf
714+
// let firstInterfaceWithMultipleGenericInstantiations =
715+
// interfaces |> List.tryPick (fun typ1 ->
716+
// table |> MultiMap.find (keyf typ1) |> List.tryPick (fun typ2 ->
717+
// if // same nominal type
718+
// tyconRefEq cenv.g (tcrefOfAppTy cenv.g typ1) (tcrefOfAppTy cenv.g typ2) &&
719+
// // different instantiations
720+
// not (typeEquivAux EraseNone cenv.g typ1 typ2)
721+
// then Some (typ1, typ2)
722+
// else None))
723+
// match firstInterfaceWithMultipleGenericInstantiations with
724+
// | None -> ()
725+
// | Some (typ1, typ2) ->
726+
// let typ1Str = NicePrint.minimalStringOfType cenv.denv typ1
727+
// let typ2Str = NicePrint.minimalStringOfType cenv.denv typ2
728+
// errorR(Error(FSComp.SR.chkMultipleGenericInterfaceInstantiations(typ1Str, typ2Str), m))
729+
// else
730+
// let groups = interfaces |> List.groupBy keyf
731+
// let errors = seq {
732+
// for (_, items) in groups do
733+
// for i1 in 0 .. items.Length - 1 do
734+
// for i2 in i1 + 1 .. items.Length - 1 do
735+
// let typ1 = items.[i1]
736+
// let typ2 = items.[i2]
737+
// match compareTypesWithRegardToTypeVariablesAndMeasures cenv.g cenv.amap m typ1 typ2 with
738+
// | ExactlyEqual -> () // exact duplicates are checked in another place
739+
// | FeasiblyEqual ->
740+
// let typ1Str = NicePrint.minimalStringOfType cenv.denv typ1
741+
// let typ2Str = NicePrint.minimalStringOfType cenv.denv typ2
742+
// if isObjectExpression then
743+
// yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariableObjectExpression(tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
744+
// else
745+
// let typStr = NicePrint.minimalStringOfType cenv.denv typ
746+
// yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariable(typStr, tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
747+
// | NotEqual -> ()
748+
// }
749+
// match Seq.tryHead errors with
750+
// | None -> ()
751+
// | Some e -> errorR(e)
752+
710753
let CheckMultipleInterfaceInstantiations cenv (typ:TType) (interfaces:TType list) isObjectExpression m =
711754
let keyf ty = assert isAppTy cenv.g ty; (tcrefOfAppTy cenv.g ty).Stamp
712-
if not(cenv.g.langVersion.SupportsFeature LanguageFeature.InterfacesWithMultipleGenericInstantiation) then
713-
let table = interfaces |> MultiMap.initBy keyf
714-
let firstInterfaceWithMultipleGenericInstantiations =
715-
interfaces |> List.tryPick (fun typ1 ->
716-
table |> MultiMap.find (keyf typ1) |> List.tryPick (fun typ2 ->
717-
if // same nominal type
718-
tyconRefEq cenv.g (tcrefOfAppTy cenv.g typ1) (tcrefOfAppTy cenv.g typ2) &&
719-
// different instantiations
720-
not (typeEquivAux EraseNone cenv.g typ1 typ2)
721-
then Some (typ1, typ2)
722-
else None))
723-
match firstInterfaceWithMultipleGenericInstantiations with
724-
| None -> ()
725-
| Some (typ1, typ2) ->
726-
let typ1Str = NicePrint.minimalStringOfType cenv.denv typ1
727-
let typ2Str = NicePrint.minimalStringOfType cenv.denv typ2
728-
errorR(Error(FSComp.SR.chkMultipleGenericInterfaceInstantiations(typ1Str, typ2Str), m))
729-
else
730-
let groups = interfaces |> List.groupBy keyf
731-
let errors = seq {
732-
for (_, items) in groups do
733-
for i1 in 0 .. items.Length - 1 do
734-
for i2 in i1 + 1 .. items.Length - 1 do
735-
let typ1 = items.[i1]
736-
let typ2 = items.[i2]
737-
let tcRef1 = tcrefOfAppTy cenv.g typ1
738-
match compareTypesWithRegardToTypeVariablesAndMeasures cenv.g cenv.amap m typ1 typ2 with
739-
| ExactlyEqual -> () // exact duplicates are checked in another place
740-
| FeasiblyEqual ->
741-
let typ1Str = NicePrint.minimalStringOfType cenv.denv typ1
742-
let typ2Str = NicePrint.minimalStringOfType cenv.denv typ2
743-
if isObjectExpression then
744-
yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariableObjectExpression(tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
745-
else
746-
let typStr = NicePrint.minimalStringOfType cenv.denv typ
747-
yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariable(typStr, tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
748-
| NotEqual -> ()
749-
}
750-
match Seq.tryHead errors with
751-
| None -> ()
752-
| Some e -> errorR(e)
755+
let groups = interfaces |> List.groupBy keyf
756+
let errors = seq {
757+
for (_, items) in groups do
758+
for i1 in 0 .. items.Length - 1 do
759+
for i2 in i1 + 1 .. items.Length - 1 do
760+
let typ1 = items.[i1]
761+
let typ2 = items.[i2]
762+
let tcRef1 = tcrefOfAppTy cenv.g typ1
763+
match compareTypesWithRegardToTypeVariablesAndMeasures cenv.g cenv.amap m typ1 typ2 with
764+
| ExactlyEqual -> ()
765+
| FeasiblyEqual ->
766+
match tryLanguageFeatureErrorOption cenv.g.langVersion LanguageFeature.InterfacesWithMultipleGenericInstantiation m with
767+
| None -> ()
768+
| Some e -> yield e
769+
let typ1Str = NicePrint.minimalStringOfType cenv.denv typ1
770+
let typ2Str = NicePrint.minimalStringOfType cenv.denv typ2
771+
if isObjectExpression then
772+
yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariableObjectExpression(tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
773+
else
774+
let typStr = NicePrint.minimalStringOfType cenv.denv typ
775+
yield (Error(FSComp.SR.typrelInterfaceWithConcreteAndVariable(typStr, tcRef1.DisplayNameWithStaticParametersAndUnderscoreTypars, typ1Str, typ2Str),m))
776+
| NotEqual ->
777+
match tryLanguageFeatureErrorOption cenv.g.langVersion LanguageFeature.InterfacesWithMultipleGenericInstantiation m with
778+
| None -> ()
779+
| Some e -> yield e
780+
}
781+
match Seq.tryHead errors with
782+
| None -> ()
783+
| Some e -> errorR(e)
753784

754785
/// Check an expression, where the expression is in a position where byrefs can be generated
755786
let rec CheckExprNoByrefs cenv env expr =

0 commit comments

Comments
 (0)