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

Commit3b4f17e

Browse files
dsymeKevinRansom
authored andcommitted
Fix 681 - Compiler error when passing named parameters to attributes (#3251)
1 parent53f022a commit3b4f17e

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

‎src/fsharp/MethodCalls.fs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,25 +286,25 @@ type CalledMeth<'T>
286286
else None)
287287
|_-> None)
288288

289-
letunassignedNamedItem=
289+
letunassignedNamedItems=
290290
namedCallerArgs|> List.filter(fun(CallerNamedArg(nm,_e))->
291291
fullCalledArgs|> List.forall(fun calledArg->
292292
match calledArg.NameOptwith
293293
| Some nm2-> nm.idText<> nm2.idText
294294
| None->true))
295295

296-
letattributeAssignedNamedItems,unassignedNamedItem=
296+
letattributeAssignedNamedItems=
297297
if isCheckingAttributeCallthen
298-
//the assignment of names toproperties is substantially for attribute specifications
299-
// permits bindings of names tonon-mutable fields and properties, sowedo that using the old
300-
//reliablecode for this later on.
301-
unassignedNamedItem,[]
298+
//The process for assigning names-->properties is substantially different for attribute specifications
299+
//because itpermitsthebindings of names toimmutable fields. Soweuse the old
300+
// code for this.
301+
unassignedNamedItems
302302
else
303-
[],unassignedNamedItem
303+
[]
304304

305-
letassignedNamedProps,unassignedNamedItem=
305+
letassignedNamedProps,unassignedNamedItems=
306306
letreturnedObjTy=if minfo.IsConstructorthen minfo.EnclosingTypeelse methodRetTy
307-
unassignedNamedItem|> List.splitChoose(fun(CallerNamedArg(id,e)asarg)->
307+
unassignedNamedItems|> List.splitChoose(fun(CallerNamedArg(id,e)asarg)->
308308
letnm= id.idText
309309
letpinfos= GetIntrinsicPropInfoSetsOfType infoReader(Some(nm),ad,AllowMultiIntfInstantiations.Yes) IgnoreOverrides id.idRange returnedObjTy
310310
letpinfos= pinfos|> ExcludeHiddenOfPropInfos g infoReader.amap m
@@ -347,7 +347,7 @@ type CalledMeth<'T>
347347

348348
letargSet={ UnnamedCalledArgs=unnamedCalledArgs; UnnamedCallerArgs=unnamedCallerArgs; ParamArrayCalledArgOpt=paramArrayCalledArgOpt; ParamArrayCallerArgs=paramArrayCallerArgs; AssignedNamedArgs=assignedNamedArgs}
349349

350-
(argSet,assignedNamedProps,unassignedNamedItem,attributeAssignedNamedItems,unnamedCalledOptArgs,unnamedCalledOutArgs))
350+
(argSet,assignedNamedProps,unassignedNamedItems,attributeAssignedNamedItems,unnamedCalledOptArgs,unnamedCalledOutArgs))
351351

352352
letargSets= argSetInfos|> List.map(fun(x,_,_,_,_,_)-> x)
353353
letassignedNamedProps= argSetInfos|> List.collect(fun(_,x,_,_,_,_)-> x)

‎src/fsharp/TypeChecker.fs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9178,7 +9178,7 @@ and GetNewInferenceTypeForMethodArg cenv env tpenv x =
91789178

91799179
/// Method calls, property lookups, attribute constructions etc. get checked through here
91809180
and TcMethodApplication
9181-
checkingAttributeCall
9181+
isCheckingAttributeCall
91829182
cenv
91839183
env
91849184
tpenv
@@ -9384,7 +9384,7 @@ and TcMethodApplication
93849384
match tyargsOpt with
93859385
| Some tyargs -> minfo.AdjustUserTypeInstForFSharpStyleIndexedExtensionMembers(tyargs)
93869386
| None -> minst
9387-
CalledMeth<SynExpr>(cenv.infoReader,Some(env.NameEnv),checkingAttributeCall, FreshenMethInfo, mMethExpr,ad,minfo,minst,callerTyArgs,pinfoOpt,callerObjArgTys,callerArgs,usesParamArrayConversion,true,objTyOpt)
9387+
CalledMeth<SynExpr>(cenv.infoReader,Some(env.NameEnv),isCheckingAttributeCall, FreshenMethInfo, mMethExpr,ad,minfo,minst,callerTyArgs,pinfoOpt,callerObjArgTys,callerArgs,usesParamArrayConversion,true,objTyOpt)
93889388

93899389
let preArgumentTypeCheckingCalledMethGroup =
93909390
[ for (minfo,pinfoOpt) in candidateMethsAndProps do
@@ -9483,7 +9483,7 @@ and TcMethodApplication
94839483
match tyargsOpt with
94849484
| Some tyargs -> minfo.AdjustUserTypeInstForFSharpStyleIndexedExtensionMembers(tyargs)
94859485
| None -> minst
9486-
CalledMeth<Expr>(cenv.infoReader,Some(env.NameEnv),checkingAttributeCall,FreshenMethInfo, mMethExpr,ad,minfo,minst,callerTyArgs,pinfoOpt,callerObjArgTys,callerArgs,usesParamArrayConversion,true,objTyOpt))
9486+
CalledMeth<Expr>(cenv.infoReader,Some(env.NameEnv),isCheckingAttributeCall,FreshenMethInfo, mMethExpr,ad,minfo,minst,callerTyArgs,pinfoOpt,callerObjArgTys,callerArgs,usesParamArrayConversion,true,objTyOpt))
94879487

94889488
let callerArgCounts = (unnamedCurriedCallerArgs.Length, namedCurriedCallerArgs.Length)
94899489
let csenv = MakeConstraintSolverEnv ContextInfo.NoContext cenv.css mMethExpr denv
@@ -9859,6 +9859,7 @@ and TcMethodApplication
98599859

98609860
// Handle post-hoc property assignments
98619861
let expr =
9862+
if isCheckingAttributeCall then expr else
98629863
if isNil finalAssignedItemSetters then expr else
98639864
// This holds the result of the call
98649865
let objv,objExpr = mkMutableCompGenLocal mMethExpr "returnVal" exprty // mutable in case it's a struct
@@ -10531,7 +10532,7 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
1053110532
| Item.CtorGroup(methodName,minfos) ->
1053210533
let meths = minfos |> List.map (fun minfo -> minfo,None)
1053310534
let afterResolution = ForNewConstructors cenv.tcSink env tyid.idRange methodName minfos
10534-
let (expr,namedCallerArgs,_),_ =
10535+
let (expr,attributeAssignedNamedItems,_),_ =
1053510536
TcMethodApplication true cenv env tpenv None [] mAttr mAttr methodName None ad PossiblyMutates false meths afterResolution NormalValUse [arg] (NewInferenceType ()) []
1053610537

1053710538
UnifyTypes cenv env mAttr ty (tyOfExpr cenv.g expr)
@@ -10540,9 +10541,9 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
1054010541
AttribExpr(e,EvalLiteralExprOrAttribArg cenv.g e)
1054110542

1054210543
let namedAttribArgMap =
10543-
namedCallerArgs |> List.map (fun (CallerNamedArg(id,CallerArg(argtyv,m,isOpt,expr))) ->
10544+
attributeAssignedNamedItems |> List.map (fun (CallerNamedArg(id,CallerArg(argtyv,m,isOpt,callerArgExpr))) ->
1054410545
if isOpt then error(Error(FSComp.SR.tcOptionalArgumentsCannotBeUsedInCustomAttribute(),m))
10545-
let m =expr.Range
10546+
let m =callerArgExpr.Range
1054610547
let setterItem, _ = ResolveLongIdentInType cenv.tcSink cenv.nameResolver env.NameEnv LookupKind.Expr m ad [id] IgnoreOverrides TypeNameResolutionInfo.Default ty
1054710548
let nm, isProp, argty =
1054810549
match setterItem with
@@ -10568,7 +10569,7 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
1056810569

1056910570
AddCxTypeMustSubsumeType ContextInfo.NoContext env.DisplayEnv cenv.css m NoTrace argty argtyv
1057010571

10571-
AttribNamedArg(nm,argty,isProp,mkAttribExprexpr))
10572+
AttribNamedArg(nm,argty,isProp,mkAttribExprcallerArgExpr))
1057210573

1057310574
match expr with
1057410575
| Expr.Op(TOp.ILCall(_,_,valu,_,_,_,_,ilMethRef,[],[],_rtys),[],args,m) ->

‎tests/fsharp/core/attributes/test.fsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,15 @@ module TestFsiLoadOfNonExistentAssembly =
13231323

13241324
do test()
13251325

1326+
// See https://github.com/Microsoft/visualfsharp/issues/681
1327+
moduleBugWithOverloadedAttributes=
1328+
1329+
typeFooAttribute(value: int)=
1330+
inherit System.Attribute()
1331+
new()=new FooAttribute(-1)
1332+
1333+
[<FooAttribute(value=42)>]
1334+
typeBar=classend
13261335

13271336
(*-------------------------------------------------------------------------
13281337
!* Test passed?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp