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

check constant first (#3130)

* check constant first

* check constant first
上级 44db9d0f
......@@ -1040,7 +1040,7 @@ let MakeMemberDataAndMangledNameForMemberVal(g,tcref,isExtrinsic,attrs,optImplSl
if n<>3 && opTakesThreeArgs then warning(Error(FSComp.SR.memberOperatorDefinitionWithNonTripleArgument(name,n),m))
if not (isNil otherArgs) then warning(Error(FSComp.SR.memberOperatorDefinitionWithCurriedArguments(name),m))
if IsMangledOpName id.idText && isExtrinsic then
if isExtrinsic && IsMangledOpName id.idText then
warning(Error(FSComp.SR.tcMemberOperatorDefinitionInExtrinsic(),id.idRange))
ValMemberInfoTransient(memberInfo,logicalName,compiledName)
......@@ -2628,7 +2628,7 @@ let FreshenObjectArgType cenv m rigid tcref isExtrinsic declaredTyconTypars =
#endif
// Struct members have a byref 'this' type (unless they are extrinsic extension members)
let thisTy =
if tcref.IsStructOrEnumTycon && not isExtrinsic then
if not isExtrinsic && tcref.IsStructOrEnumTycon then
mkByrefTy cenv.g objTy
else
objTy
......@@ -9584,13 +9584,13 @@ and TcMethodApplication
elif isDelegateTy cenv.g calledArgTy && isFunTy cenv.g callerArgTy then
CoerceFromFSharpFuncToDelegate cenv.g cenv.amap cenv.infoReader ad callerArgTy m callerArgExpr calledArgTy
elif isLinqExpressionTy cenv.g calledArgTy && isDelegateTy cenv.g (destLinqExpressionTy cenv.g calledArgTy) && isFunTy cenv.g callerArgTy then
elif isLinqExpressionTy cenv.g calledArgTy && isDelegateTy cenv.g (destLinqExpressionTy cenv.g calledArgTy) && isFunTy cenv.g callerArgTy then
let delegateTy = destLinqExpressionTy cenv.g calledArgTy
let expr = CoerceFromFSharpFuncToDelegate cenv.g cenv.amap cenv.infoReader ad callerArgTy m callerArgExpr delegateTy
mkCallQuoteToLinqLambdaExpression cenv.g m delegateTy (Expr.Quote(expr, ref None, false, m, mkQuotedExprTy cenv.g delegateTy))
// auto conversions to quotations (to match auto conversions to LINQ expressions)
elif reflArgInfo.AutoQuote && isQuotedExprTy cenv.g calledArgTy && not (isQuotedExprTy cenv.g callerArgTy) then
elif reflArgInfo.AutoQuote && isQuotedExprTy cenv.g calledArgTy && not (isQuotedExprTy cenv.g callerArgTy) then
match reflArgInfo with
| ReflectedArgInfo.Quote true ->
mkCallLiftValueWithDefn cenv.g m calledArgTy callerArgExpr
......@@ -10326,14 +10326,16 @@ and TcNormalizedBinding declKind (cenv:cenv) env tpenv overallTy safeThisValOpt
// Check other attributes
let hasLiteralAttr,konst = TcLiteral cenv overallExprTy env tpenv (valAttribs,rhsExpr)
if hasLiteralAttr && isThreadStatic then
errorR(Error(FSComp.SR.tcIllegalAttributesForLiteral(),mBinding))
if hasLiteralAttr && isMutable then
errorR(Error(FSComp.SR.tcLiteralCannotBeMutable(),mBinding))
if hasLiteralAttr && isInline then
errorR(Error(FSComp.SR.tcLiteralCannotBeInline(),mBinding))
if hasLiteralAttr && not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(),mBinding))
if hasLiteralAttr then
if isThreadStatic then
errorR(Error(FSComp.SR.tcIllegalAttributesForLiteral(),mBinding))
if isMutable then
errorR(Error(FSComp.SR.tcLiteralCannotBeMutable(),mBinding))
if isInline then
errorR(Error(FSComp.SR.tcLiteralCannotBeInline(),mBinding))
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(),mBinding))
CheckedBindingInfo(inlineFlag,valAttribs,doc,tcPatPhase2,flex,nameToPrelimValSchemeMap,rhsExprChecked,argAndRetAttribs,overallPatTy,mBinding,spBind,compgen,konst,isFixed),tpenv
......@@ -10927,8 +10929,7 @@ and AnalyzeRecursiveStaticMemberOrValDecl (cenv, envinner: TcEnv, tpenv, declKin
CheckMemberFlags cenv.g None newslotsOK overridesOK memberFlags id.idRange
CheckForNonAbstractInterface declKind tcref memberFlags id.idRange
if tcref.Deref.IsExceptionDecl &&
(memberFlags.MemberKind = MemberKind.Constructor) then
if memberFlags.MemberKind = MemberKind.Constructor && tcref.Deref.IsExceptionDecl then
error(Error(FSComp.SR.tcConstructorsDisallowedInExceptionAugmentation(),id.idRange))
let isExtrinsic = (declKind = ExtrinsicExtensionBinding)
......@@ -11753,7 +11754,7 @@ exception NotUpperCaseConstructor of range
let CheckNamespaceModuleOrTypeName (g:TcGlobals) (id:Ident) =
// type names '[]' etc. are used in fslib
if not g.compilingFslib && id.idText.IndexOfAny(IllegalCharactersInTypeAndNamespaceNames) <> -1 then
if not g.compilingFslib && id.idText.IndexOfAny(IllegalCharactersInTypeAndNamespaceNames) <> -1 then
errorR(Error(FSComp.SR.tcInvalidNamespaceModuleTypeUnionName(),id.idRange))
let CheckDuplicates (idf : _ -> Ident) k elems =
......@@ -11761,7 +11762,7 @@ let CheckDuplicates (idf : _ -> Ident) k elems =
elems |> List.iteri (fun j uc2 ->
let id1 = (idf uc1)
let id2 = (idf uc2)
if j > i && id1.idText = id2.idText then
if j > i && id1.idText = id2.idText then
errorR (Duplicate(k,id1.idText,id1.idRange))))
elems
......@@ -11794,7 +11795,7 @@ module TcRecdUnionAndEnumDeclarations = begin
if isVolatile then
error(Error(FSComp.SR.tcVolatileOnlyOnClassLetBindings(),m))
if isIncrClass && (not zeroInit || not isMutable) then errorR(Error(FSComp.SR.tcUninitializedValFieldsMustBeMutable(),m))
if isIncrClass && (not zeroInit || not isMutable) then errorR(Error(FSComp.SR.tcUninitializedValFieldsMustBeMutable(),m))
if isStatic && (not zeroInit || not isMutable || vis <> Some SynAccess.Private ) then errorR(Error(FSComp.SR.tcStaticValFieldsMustBeMutableAndPrivate(),m))
let konst = if zeroInit then Some Const.Zero else None
let rfspec = MakeRecdFieldSpec cenv env parent (isStatic,konst,ty',attrsForProperty,attrsForField,id,isMutable,isVolatile,xmldoc,vis,m)
......@@ -12958,7 +12959,7 @@ module MutRecBindingChecking =
| TyparKind.Measure,false -> error(Error(FSComp.SR.tcMeasureDeclarationsRequireStaticMembers(), m))
| _ -> ()
if tcref.IsStructOrEnumTycon && not isStatic then
if not isStatic && tcref.IsStructOrEnumTycon then
let allDo = letBinds |> List.forall (function (Binding(_,DoBinding,_,_,_,_,_,_,_,_,_,_)) -> true | _ -> false)
// Code for potential future design change to allow functions-compiled-as-members in structs
if allDo then
......@@ -13175,9 +13176,8 @@ module MutRecBindingChecking =
let envNonRec = (envNonRec,binds) ||> List.fold (fun acc bind -> AddLocalValPrimitive bind.Var acc)
// Check to see that local bindings and members don't have the same name and check some other adhoc conditions
for bind in binds do
if HasFSharpAttributeOpt cenv.g cenv.g.attrib_DllImportAttribute bind.Var.Attribs && not isStatic then
for bind in binds do
if not isStatic && HasFSharpAttributeOpt cenv.g cenv.g.attrib_DllImportAttribute bind.Var.Attribs then
errorR(Error(FSComp.SR.tcDllImportNotAllowed(),bind.Var.Range))
let nm = bind.Var.DisplayName
......@@ -16041,7 +16041,7 @@ module TcDeclarations =
let preEstablishedHasDefaultCtor =
members |> List.exists (function
| SynMemberSig.Member (valSpfn,memberFlags,_) ->
memberFlags.MemberKind=MemberKind.Constructor &&
memberFlags.MemberKind=MemberKind.Constructor &&
// REVIEW: This is a syntactic approximation
(match valSpfn.SynType, valSpfn.SynInfo.ArgInfos with
| SynType.Fun (SynType.LongIdent (LongIdentWithDots([id],_)), _, _), [[_]] when id.idText = "unit" -> true
......@@ -16818,7 +16818,7 @@ let ApplyDefaults cenv g denvAtEnd m mexpr extraAttribs =
match tpc with
| TyparConstraint.DefaultsTo(priority2,ty2,m) when priority2 = priority ->
let ty1 = mkTyparTy tp
if not tp.IsSolved && not (typeEquiv cenv.g ty1 ty2) then
if not tp.IsSolved && not (typeEquiv cenv.g ty1 ty2) then
let csenv = MakeConstraintSolverEnv ContextInfo.NoContext cenv.css m denvAtEnd
TryD (fun () -> ConstraintSolver.SolveTyparEqualsTyp csenv 0 m NoTrace ty1 ty2)
(fun e -> solveTypAsError cenv denvAtEnd m ty1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册