-
Notifications
You must be signed in to change notification settings - Fork 830
Name resolution: keep type vars in subsequent checks #16456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
7763fa0
0b9c0ad
b3a8ec0
0ad6b15
b0f0235
12d3d9a
0649805
a2a7341
b9b1aba
58a6e03
e1679c4
7fa6132
05dd468
91b796d
798e069
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -767,7 +767,7 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst = | |
| | SynMeasure.One _ -> Measure.One | ||
| | SynMeasure.Named(tc, m) -> | ||
| let ad = env.eAccessRights | ||
| let _, tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Use OpenQualified env.eNameResEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No) | ||
| let _, tcref, _ = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Use OpenQualified env.eNameResEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No) | ||
| match tcref.TypeOrMeasureKind with | ||
| | TyparKind.Type -> error(Error(FSComp.SR.tcExpectedUnitOfMeasureNotType(), m)) | ||
| | TyparKind.Measure -> Measure.Const tcref | ||
|
|
@@ -4458,7 +4458,7 @@ and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tp | |
| let m = synLongId.Range | ||
| let ad = env.eAccessRights | ||
|
|
||
| let tinstEnclosing, tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver occ OpenQualified env.NameEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No) | ||
| let tinstEnclosing, tcref, inst = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver occ OpenQualified env.NameEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No) | ||
|
|
||
| CheckIWSAM cenv env checkConstraints iwsam m tcref | ||
|
|
||
|
|
@@ -4472,15 +4472,15 @@ and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tp | |
| | _, TyparKind.Measure -> | ||
| TType_measure (Measure.Const tcref), tpenv | ||
| | _, TyparKind.Type -> | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinstEnclosing [] | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinstEnclosing [] inst | ||
|
|
||
| /// Some.Long.TypeName<ty1, ty2> | ||
| /// ty1 SomeLongTypeName | ||
| and TcLongIdentAppType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv longId postfix args m = | ||
| let (SynLongIdent(tc, _, _)) = longId | ||
| let ad = env.eAccessRights | ||
|
|
||
| let tinstEnclosing, tcref = | ||
| let tinstEnclosing, tcref, inst = | ||
| let tyResInfo = TypeNameResolutionStaticArgsInfo.FromTyArgs args.Length | ||
| ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInType OpenQualified env.eNameResEnv ad tc tyResInfo PermitDirectReferenceToGeneratedType.No | ||
| |> ForceRaise | ||
|
|
@@ -4499,7 +4499,7 @@ and TcLongIdentAppType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env | |
| | _, TyparKind.Type -> | ||
| if postfix && tcref.Typars m |> List.exists (fun tp -> match tp.Kind with TyparKind.Measure -> true | _ -> false) then | ||
| error(Error(FSComp.SR.tcInvalidUnitsOfMeasurePrefix(), m)) | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinstEnclosing args | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinstEnclosing args inst | ||
|
|
||
| | _, TyparKind.Measure -> | ||
| match args, postfix with | ||
|
|
@@ -4518,8 +4518,8 @@ and TcNestedAppType (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synL | |
| let leftTy, tpenv = TcType cenv newOk checkConstraints occ iwsam env tpenv synLeftTy | ||
| match leftTy with | ||
| | AppTy g (tcref, tinst) -> | ||
| let tcref = ResolveTypeLongIdentInTyconRef cenv.tcSink cenv.nameResolver env.eNameResEnv (TypeNameResolutionInfo.ResolveToTypeRefs (TypeNameResolutionStaticArgsInfo.FromTyArgs args.Length)) ad m tcref longId | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinst args | ||
| let tcref, inst = ResolveTypeLongIdentInTyconRef cenv.tcSink cenv.nameResolver env.eNameResEnv (TypeNameResolutionInfo.ResolveToTypeRefs (TypeNameResolutionStaticArgsInfo.FromTyArgs args.Length)) ad m tcref longId | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref tinst args inst | ||
| | _ -> | ||
| error(Error(FSComp.SR.tcTypeHasNoNestedTypes(), m)) | ||
|
|
||
|
|
@@ -4943,7 +4943,7 @@ and TcProvidedTypeApp (cenv: cenv) env tpenv tcref args m = | |
| /// Note that the generic type may be a nested generic type List<T>.ListEnumerator<U>. | ||
| /// In this case, 'argsR is only the instantiation of the suffix type arguments, and pathTypeArgs gives | ||
| /// the prefix of type arguments. | ||
| and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv m tcref pathTypeArgs (synArgTys: SynType list) = | ||
| and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv m tcref pathTypeArgs (synArgTys: SynType list) (tinst: TypeInst) = | ||
| let g = cenv.g | ||
| CheckTyconAccessible cenv.amap m env.AccessRights tcref |> ignore | ||
| CheckEntityAttributes g tcref m |> CommitOperationResult | ||
|
|
@@ -4954,16 +4954,22 @@ and TcTypeApp (cenv: cenv) newOk checkConstraints occ env tpenv m tcref pathType | |
| if tcref.Deref.IsProvided then TcProvidedTypeApp cenv env tpenv tcref synArgTys m else | ||
| #endif | ||
|
|
||
| let tps, _, tinst, _ = FreshenTyconRef2 g m tcref | ||
|
|
||
| // If we're not checking constraints, i.e. when we first assert the super/interfaces of a type definition, then just | ||
| // clear the constraint lists of the freshly generated type variables. A little ugly but fairly localized. | ||
| if checkConstraints = NoCheckCxs then tps |> List.iter (fun tp -> tp.SetConstraints []) | ||
| let synArgTysLength = synArgTys.Length | ||
| let pathTypeArgsLength = pathTypeArgs.Length | ||
| if tinst.Length <> pathTypeArgsLength + synArgTysLength then | ||
| error (TyconBadArgs(env.DisplayEnv, tcref, pathTypeArgsLength + synArgTysLength, m)) | ||
|
|
||
| let tps = tinst |> List.skip pathTypeArgsLength |> List.map (fun t -> | ||
| match t with | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't probably match on ttype directly, need do stripping first
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure of this holds for a type instantiation, but it is a good point to add a test case with a type alias as a typar to see what it does. If we stripped, we would lose the type alias and then it couldn't be searched for as a separate symbol... ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it'd be what we want to achieve here. I'm unwrapping the type variables produced by name resolution logic here, I probably don't want to change them in any way. Another approach could be to refactor more places and to pass the typar instantiation explicitly, but it seems that simply unwrapping it like this works for the cases we're interested in here, i.e. to make the types flow into subsequent checking phases after reporting. |
||
| | TType_var(typar, _) | ||
| | TType_measure(Measure.Var typar) -> typar | ||
| | t -> failwith $"TcTypeApp: {t}" | ||
| ) | ||
|
|
||
| // If we're not checking constraints, i.e. when we first assert the super/interfaces of a type definition, then just | ||
| // clear the constraint lists of the freshly generated type variables. A little ugly but fairly localized. | ||
| if checkConstraints = NoCheckCxs then tps |> List.iter (fun tp -> tp.SetConstraints []) | ||
|
|
||
| let argTys, tpenv = | ||
| // Get the suffix of typars | ||
| let tpsForArgs = List.skip (tps.Length - synArgTysLength) tps | ||
|
|
@@ -5009,9 +5015,9 @@ and TcNestedTypeApplication (cenv: cenv) newOk checkConstraints occ iwsam env tp | |
| error(Error(FSComp.SR.tcTypeHasNoNestedTypes(), mWholeTypeApp)) | ||
|
|
||
| match ty with | ||
| | TType_app(tcref, _, _) -> | ||
| | TType_app(tcref, inst, _) -> | ||
| CheckIWSAM cenv env checkConstraints iwsam mWholeTypeApp tcref | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv mWholeTypeApp tcref pathTypeArgs tyargs | ||
| TcTypeApp cenv newOk checkConstraints occ env tpenv mWholeTypeApp tcref pathTypeArgs tyargs inst | ||
| | _ -> | ||
| error(InternalError("TcNestedTypeApplication: expected type application", mWholeTypeApp)) | ||
|
|
||
|
|
@@ -8163,10 +8169,10 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) = | |
| if (match delayed with [DelayedTypeApp _] | [] -> true | _ -> false) then | ||
| let (TypeNameResolutionInfo(_, staticArgsInfo)) = GetLongIdentTypeNameInfo delayed | ||
| match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad longId staticArgsInfo PermitDirectReferenceToGeneratedType.No with | ||
| | Result (tinstEnclosing, tcref) when IsEntityAccessible cenv.amap m ad tcref -> | ||
| | Result (tinstEnclosing, tcref, inst) when IsEntityAccessible cenv.amap m ad tcref -> | ||
| match delayed with | ||
| | [DelayedTypeApp (tyargs, _, mExprAndTypeArgs)] -> | ||
| TcTypeApp cenv NewTyparsOK CheckCxs ItemOccurence.UseInType env tpenv mExprAndTypeArgs tcref tinstEnclosing tyargs |> ignore | ||
| TcTypeApp cenv NewTyparsOK CheckCxs ItemOccurence.UseInType env tpenv mExprAndTypeArgs tcref tinstEnclosing tyargs inst |> ignore | ||
| | _ -> () | ||
| true // resolved to a type name, done with checks | ||
| | _ -> | ||
|
|
@@ -10858,7 +10864,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn | |
|
|
||
| match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad tycon TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No with | ||
| | Exception err -> raze err | ||
| | Result(tinstEnclosing, tcref) -> success(TcTypeApp cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute env tpenv mAttr tcref tinstEnclosing []) | ||
| | Result(tinstEnclosing, tcref, inst) -> success(TcTypeApp cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute env tpenv mAttr tcref tinstEnclosing [] inst) | ||
|
|
||
| ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText))) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.