提交 6453d1b5 编写于 作者: S Steffen Forkmann 提交者: Kevin Ransom (msft)

Restructure NameResolution (#4471)

上级 1d2c78e2
此差异已折叠。
......@@ -451,13 +451,13 @@ type ResultCollectionSettings =
| AtMostOneResult
/// Resolve a long identifier to a namespace or module.
val internal ResolveLongIndentAsModuleOrNamespace : TcResultsSink -> ResultCollectionSettings -> Import.ImportMap -> range -> FullyQualifiedFlag -> NameResolutionEnv -> AccessorDomain -> Ident list -> isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list >
val internal ResolveLongIndentAsModuleOrNamespace : TcResultsSink -> ResultCollectionSettings -> Import.ImportMap -> range -> bool -> FullyQualifiedFlag -> NameResolutionEnv -> AccessorDomain -> Ident -> Ident list -> isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list >
/// Resolve a long identifier to an object constructor.
val internal ResolveObjectConstructor : NameResolver -> DisplayEnv -> range -> AccessorDomain -> TType -> ResultOrException<Item>
/// Resolve a long identifier using type-qualified name resolution.
val internal ResolveLongIdentInType : TcResultsSink -> NameResolver -> NameResolutionEnv -> LookupKind -> range -> AccessorDomain -> Ident list -> FindMemberFlag -> TypeNameResolutionInfo -> TType -> Item * Ident list
val internal ResolveLongIdentInType : TcResultsSink -> NameResolver -> NameResolutionEnv -> LookupKind -> range -> AccessorDomain -> Ident -> FindMemberFlag -> TypeNameResolutionInfo -> TType -> Item * Ident list
/// Resolve a long identifier when used in a pattern.
val internal ResolvePatternLongIdent : TcResultsSink -> NameResolver -> WarnOnUpperFlag -> bool -> range -> AccessorDomain -> NameResolutionEnv -> TypeNameResolutionInfo -> Ident list -> Item
......
......@@ -697,13 +697,16 @@ let ImplicitlyOpenOwnNamespace tcSink g amap scopem enclosingNamespacePath env =
| Some(_, rest) -> rest
| None -> enclosingNamespacePath
let ad = env.eAccessRights
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap scopem OpenQualified env.eNameResEnv ad enclosingNamespacePathToOpen true with
| Result modrefs ->
let modrefs = List.map p23 modrefs
let openDecl = OpenDeclaration.Create (enclosingNamespacePathToOpen, modrefs, scopem, true)
OpenModulesOrNamespaces tcSink g amap scopem false env modrefs openDecl
| Exception _ -> env
match enclosingNamespacePathToOpen with
| id::rest ->
let ad = env.eAccessRights
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap scopem true OpenQualified env.eNameResEnv ad id rest true with
| Result modrefs ->
let modrefs = List.map p23 modrefs
let openDecl = OpenDeclaration.Create (enclosingNamespacePathToOpen, modrefs, scopem, true)
OpenModulesOrNamespaces tcSink g amap scopem false env modrefs openDecl
| Exception _ -> env
| _ -> env
//-------------------------------------------------------------------------
......@@ -6805,7 +6808,7 @@ and TcConstExpr cenv overallTy env m tpenv c =
let expr =
let modName = "NumericLiteral" + suffix
let ad = env.eAccessRights
match ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m OpenQualified env.eNameResEnv ad [ident (modName, m)] false with
match ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m true OpenQualified env.eNameResEnv ad (ident (modName, m)) [] false with
| Result []
| Exception _ -> error(Error(FSComp.SR.tcNumericLiteralRequiresModule(modName), m))
| Result ((_, mref, _) :: _) ->
......@@ -10632,13 +10635,13 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
attributeAssignedNamedItems |> List.map (fun (CallerNamedArg(id, CallerArg(argtyv, m, isOpt, callerArgExpr))) ->
if isOpt then error(Error(FSComp.SR.tcOptionalArgumentsCannotBeUsedInCustomAttribute(), m))
let m = callerArgExpr.Range
let setterItem, _ = ResolveLongIdentInType cenv.tcSink cenv.nameResolver env.NameEnv LookupKind.Expr m ad [id] IgnoreOverrides TypeNameResolutionInfo.Default ty
let setterItem, _ = ResolveLongIdentInType cenv.tcSink cenv.nameResolver env.NameEnv LookupKind.Expr m ad id IgnoreOverrides TypeNameResolutionInfo.Default ty
let nm, isProp, argty =
match setterItem with
| Item.Property (_, [pinfo]) ->
if not pinfo.HasSetter then
errorR(Error(FSComp.SR.tcPropertyCannotBeSet0(), m))
id.idText, true, pinfo.GetPropertyType(cenv.amap, m)
id.idText, true, pinfo.GetPropertyType(cenv.amap, m)
| Item.ILField finfo ->
CheckILFieldInfoAccessible cenv.g cenv.amap m ad finfo
CheckILFieldAttributes cenv.g finfo m
......@@ -12081,10 +12084,13 @@ let TcTyconMemberSpecs cenv env containerInfo declKind tpenv (augSpfn: SynMember
let TcModuleOrNamespaceLidAndPermitAutoResolve tcSink env amap (longId : Ident list) =
let ad = env.eAccessRights
let m = longId |> List.map (fun id -> id.idRange) |> List.reduce unionRanges
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap m OpenQualified env.eNameResEnv ad longId true with
| Result res -> Result res
| Exception err -> raze err
match longId with
| [] -> Result []
| id::rest ->
let m = longId |> List.map (fun id -> id.idRange) |> List.reduce unionRanges
match ResolveLongIndentAsModuleOrNamespace tcSink ResultCollectionSettings.AllResults amap m true OpenQualified env.eNameResEnv ad id rest true with
| Result res -> Result res
| Exception err -> raze err
let TcOpenDecl tcSink (g:TcGlobals) amap m scopem env (longId : Ident list) =
let modrefs = ForceRaise (TcModuleOrNamespaceLidAndPermitAutoResolve tcSink env amap longId)
......@@ -13581,12 +13587,17 @@ module MutRecBindingChecking =
/// Check a "module X = A.B.C" module abbreviation declaration
let TcModuleAbbrevDecl (cenv:cenv) scopem env (id, p, m) =
let ad = env.eAccessRights
let mvvs = ForceRaise (ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m OpenQualified env.eNameResEnv ad p false)
let modrefs = mvvs |> List.map p23
if not (List.isEmpty modrefs) && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
let resolved =
match p with
| [] -> Result []
| id::rest -> ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m true OpenQualified env.eNameResEnv ad id rest false
let mvvs = ForceRaise resolved
if isNil mvvs then env else
let modrefs = mvvs |> List.map p23
if not (isNil modrefs) && modrefs |> List.forall (fun modref -> modref.IsNamespace) then
errorR(Error(FSComp.SR.tcModuleAbbreviationForNamespace(fullDisplayTextOfModRef (List.head modrefs)), m))
let modrefs = modrefs |> List.filter (fun mvv -> not mvv.IsNamespace)
if List.isEmpty modrefs then env else
if isNil modrefs then env else
modrefs |> List.iter (fun modref -> CheckEntityAttributes cenv.g modref m |> CommitOperationResult)
let env = AddModuleAbbreviationAndReport cenv.tcSink scopem id modrefs env
env
......@@ -16364,7 +16375,11 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
| SynModuleSigDecl.ModuleAbbrev (id, p, m) ->
let ad = env.eAccessRights
let mvvs = ForceRaise (ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m OpenQualified env.eNameResEnv ad p false)
let resolved =
match p with
| [] -> Result []
| id::rest -> ResolveLongIndentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m true OpenQualified env.eNameResEnv ad id rest false
let mvvs = ForceRaise resolved
let scopem = unionRanges m endm
let unfilteredModrefs = mvvs |> List.map p23
......
......@@ -3631,6 +3631,13 @@ atomicExprQualification:
| identOrOp
{ let idm = rhs parseState 1
(fun e lhsm dotm -> mkSynDot dotm lhsm e $1) }
| GLOBAL
{ (fun e lhsm dotm ->
reportParseErrorAt (rhs parseState 3) (FSComp.SR.nrGlobalUsedOnlyAsFirstName())
let fixedLhsm = mkRange lhsm.FileName lhsm.Start dotm.End // previous lhsm is wrong after 'recover'
mkSynDotMissing dotm fixedLhsm e) }
| /* empty */
{ (fun e lhsm dotm ->
reportParseErrorAt dotm (FSComp.SR.parsMissingQualificationAfterDot())
......
// #ErrorMessages #NameResolution
//<Expects status="error" span="(4,36)" id="FS1126">'global' may only be used as the first name in a qualified path</Expects>
let x = global.System.String.Empty.global.System.String.Empty
exit 0
SOURCE=E_RecordFieldProposal.fs # E_RecordFieldProposal
SOURCE=E_GlobalQualifierAfterDot.fs # E_GlobalQualifierAfterDot
SOURCE=E_FieldNotInRecord.fs # E_FieldNotInRecord
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册