Skip to content
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

Merge main to release/dev17.5 #14111

Merged
merged 13 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Compiler/Checking/AugmentWithHashCompare.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ open Internal.Utilities.Library
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.Xml
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.TypedTree
Expand Down Expand Up @@ -856,8 +855,7 @@ let slotImplMethod (final, c, slotsig) : ValMemberInfo =
IsFinal=final
IsOverrideOrExplicitImpl=true
GetterOrSetterIsCompilerGenerated=false
MemberKind=SynMemberKind.Member
Trivia=SynMemberFlagsTrivia.Zero}
MemberKind=SynMemberKind.Member }
IsImplemented=false
ApparentEnclosingEntity=c}

Expand All @@ -868,8 +866,7 @@ let nonVirtualMethod c : ValMemberInfo =
IsFinal=false
IsOverrideOrExplicitImpl=false
GetterOrSetterIsCompilerGenerated=false
MemberKind=SynMemberKind.Member
Trivia=SynMemberFlagsTrivia.Zero}
MemberKind=SynMemberKind.Member }
IsImplemented=false
ApparentEnclosingEntity=c}

Expand Down
51 changes: 38 additions & 13 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,22 @@ let CheckDuplicates (idf: _ -> Ident) k elems =
errorR (Duplicate(k, id1.idText, id1.idRange))))
elems


let private CheckDuplicatesArgNames (synVal: SynValSig) m =
let argNames = synVal.SynInfo.ArgNames |> List.duplicates
for name in argNames do
errorR(Error((FSComp.SR.chkDuplicatedMethodParameter(name), m)))

let private CheckDuplicatesAbstractMethodParmsSig (typeSpecs: SynTypeDefnSig list) =
for SynTypeDefnSig(typeRepr= trepr) in typeSpecs do
match trepr with
| SynTypeDefnSigRepr.ObjectModel(_, synMemberSigs, _) ->
for sms in synMemberSigs do
match sms with
| SynMemberSig.Member(synValSig, _, m) ->
CheckDuplicatesArgNames synValSig m
| _ -> ()
| _ -> ()

module TcRecdUnionAndEnumDeclarations =

let CombineReprAccess parent vis =
Expand Down Expand Up @@ -437,13 +452,13 @@ module TcRecdUnionAndEnumDeclarations =
| _ -> ()
rfspec

let TcAnonFieldDecl cenv env parent tpenv nm (SynField(Attributes attribs, isStatic, idOpt, ty, isMutable, xmldoc, vis, m)) =
let TcAnonFieldDecl cenv env parent tpenv nm (SynField(Attributes attribs, isStatic, idOpt, ty, isMutable, xmldoc, vis, m, _)) =
let mName = m.MakeSynthetic()
let id = match idOpt with None -> mkSynId mName nm | Some id -> id
let xmlDoc = xmldoc.ToXmlDoc(true, Some [])
TcFieldDecl cenv env parent false tpenv (isStatic, attribs, id, idOpt.IsNone, ty, isMutable, xmlDoc, vis, m)

let TcNamedFieldDecl cenv env parent isIncrClass tpenv (SynField(Attributes attribs, isStatic, id, ty, isMutable, xmldoc, vis, m)) =
let TcNamedFieldDecl cenv env parent isIncrClass tpenv (SynField(Attributes attribs, isStatic, id, ty, isMutable, xmldoc, vis, m, _)) =
match id with
| None -> error (Error(FSComp.SR.tcFieldRequiresName(), m))
| Some id ->
Expand Down Expand Up @@ -479,10 +494,10 @@ module TcRecdUnionAndEnumDeclarations =
match seen.TryGetValue f.LogicalName with
| true, synField ->
match sf, synField with
| SynField(_, _, Some id, _, _, _, _, _), SynField(_, _, Some _, _, _, _, _, _) ->
| SynField(idOpt = Some id), SynField(idOpt = Some _) ->
error(Error(FSComp.SR.tcFieldNameIsUsedModeThanOnce(id.idText), id.idRange))
| SynField(_, _, Some id, _, _, _, _, _), SynField(_, _, None, _, _, _, _, _)
| SynField(_, _, None, _, _, _, _, _), SynField(_, _, Some id, _, _, _, _, _) ->
| SynField(idOpt = Some id), SynField(idOpt = None)
| SynField(idOpt = None), SynField(idOpt = Some id) ->
error(Error(FSComp.SR.tcFieldNameConflictsWithGeneratedNameForAnonymousField(id.idText), id.idRange))
| _ -> assert false
| _ ->
Expand Down Expand Up @@ -2362,7 +2377,7 @@ module EstablishTypeDefinitionCores =
for SynUnionCase (caseType=args; range=m) in unionCases do
match args with
| SynUnionCaseKind.Fields flds ->
for SynField(_, _, _, ty, _, _, _, m) in flds do
for SynField(fieldType = ty; range = m) in flds do
let tyR, _ = TcTypeAndRecover cenv NoNewTypars NoCheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv ty
yield (tyR, m)

Expand All @@ -2379,7 +2394,7 @@ module EstablishTypeDefinitionCores =

| SynTypeDefnSimpleRepr.General (_, _, _, fields, _, _, implicitCtorSynPats, _) when tycon.IsFSharpStructOrEnumTycon -> // for structs
for field in fields do
let (SynField(_, isStatic, _, ty, _, _, _, m)) = field
let (SynField(isStatic = isStatic; fieldType = ty; range = m)) = field
if not isStatic then
let tyR, _ = TcTypeAndRecover cenv NoNewTypars NoCheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv ty
yield (tyR, m)
Expand All @@ -2399,7 +2414,7 @@ module EstablishTypeDefinitionCores =
yield (ty, m)

| SynTypeDefnSimpleRepr.Record (_, fields, _) ->
for SynField(_, _, _, ty, _, _, _, m) in fields do
for SynField(fieldType = ty; range = m) in fields do
let tyR, _ = TcTypeAndRecover cenv NoNewTypars NoCheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv ty
yield (tyR, m)

Expand Down Expand Up @@ -3946,6 +3961,14 @@ module TcDeclarations =
| SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m))
| _ -> ()
| ds ->
// Check for duplicated parameters in abstract methods
for slot in ds do
if isAbstractSlot slot then
match slot with
| SynMemberDefn.AbstractSlot (synVal, _, m) ->
CheckDuplicatesArgNames synVal m
| _ -> ()

// Classic class construction
let _, ds = List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isInherit;isField;isTycon]) ds
match ds with
Expand Down Expand Up @@ -3975,7 +3998,7 @@ module TcDeclarations =
| SynTypeDefnRepr.ObjectModel(kind, cspec, m) ->
let cspec = desugarGetSetMembers cspec
CheckMembersForm cspec
let fields = cspec |> List.choose (function SynMemberDefn.ValField (f, _) -> Some f | _ -> None)
let fields = cspec |> List.choose (function SynMemberDefn.ValField (fieldInfo = f) -> Some f | _ -> None)
let implements2 = cspec |> List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None)
let inherits =
cspec |> List.choose (function
Expand Down Expand Up @@ -4033,7 +4056,7 @@ module TcDeclarations =
// Convert auto properties to member bindings in the post-list
let rec postAutoProps memb =
match memb with
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; accessibility=access; getSetRange=mGetSetOpt) ->
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; accessibility=access; trivia = { GetSetKeyword = mGetSetOpt }) ->
let mMemberPortion = id.idRange
// Only the keep the non-field-targeted attributes
let attribs = attribs |> List.filter (fun a -> match a.Target with Some t when t.idText = "field" -> false | _ -> true)
Expand Down Expand Up @@ -4351,7 +4374,8 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
let _, _, _, env = TcExceptionDeclarations.TcExnSignature cenv env parent emptyUnscopedTyparEnv (edef, scopem)
return env

| SynModuleSigDecl.Types (typeSpecs, m) ->
| SynModuleSigDecl.Types (typeSpecs, m) ->
CheckDuplicatesAbstractMethodParmsSig typeSpecs
let scopem = unionRanges m endm
let mutRecDefns = typeSpecs |> List.map MutRecShape.Tycon
let env = TcDeclarations.TcMutRecSignatureDecls cenv env parent typeNames emptyUnscopedTyparEnv m scopem None mutRecDefns
Expand Down Expand Up @@ -4521,7 +4545,8 @@ and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (d
let rec loop isNamespace moduleRange defs: MutRecSigsInitialData =
((true, true), defs) ||> List.collectFold (fun (openOk, moduleAbbrevOk) def ->
match def with
| SynModuleSigDecl.Types (typeSpecs, _) ->
| SynModuleSigDecl.Types (typeSpecs, _) ->
CheckDuplicatesAbstractMethodParmsSig typeSpecs
let decls = typeSpecs |> List.map MutRecShape.Tycon
decls, (false, false)

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6705,7 +6705,7 @@ and TcObjectExprBinding (cenv: cenv) (env: TcEnv) implTy tpenv (absSlotInfo, bin
| SynPat.Named (SynIdent(id,_), _, _, _), None ->
let bindingRhs = PushOnePatternToRhs cenv true (mkSynThisPatVar (ident (CompilerGeneratedName "this", id.idRange))) bindingRhs
let logicalMethId = id
let memberFlags = OverrideMemberFlags SynMemberFlagsTrivia.Zero SynMemberKind.Member
let memberFlags = OverrideMemberFlags SynMemberKind.Member
bindingRhs, logicalMethId, memberFlags

| SynPat.InstanceMember(thisId, memberId, _, _, _), Some memberFlags ->
Expand Down Expand Up @@ -8579,7 +8579,7 @@ and TcImplicitOpItemThen (cenv: cenv) overallTy env id sln tpenv mItem delayed =

let vs, ves = argTys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg" + string i) ty) |> List.unzip

let memberFlags = StaticMemberFlags SynMemberFlagsTrivia.Zero SynMemberKind.Member
let memberFlags = StaticMemberFlags SynMemberKind.Member
let logicalCompiledName = ComputeLogicalName id memberFlags
let traitInfo = TTrait(argTys, logicalCompiledName, memberFlags, argTys, Some retTy, sln)

Expand Down
9 changes: 4 additions & 5 deletions src/Compiler/Checking/CheckIncrementalClasses.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ open FSharp.Compiler.CompilerGlobalState
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.NameResolution
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.SyntaxTreeOps
open FSharp.Compiler.Text
open FSharp.Compiler.Xml
Expand Down Expand Up @@ -122,7 +121,7 @@ let TcImplicitCtorLhs_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, attr

// NOTE: no attributes can currently be specified for the implicit constructor
let attribs = TcAttributes cenv env (AttributeTargets.Constructor ||| AttributeTargets.Method) attrs
let memberFlags = CtorMemberFlags SynMemberFlagsTrivia.Zero
let memberFlags = CtorMemberFlags

let synArgInfos = List.map (SynInfo.InferSynArgInfoFromSimplePat []) spats
let valSynData = SynValInfo([synArgInfos], SynInfo.unnamedRetVal)
Expand Down Expand Up @@ -150,8 +149,8 @@ let TcImplicitCtorLhs_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, attr
let cctorTy = mkFunTy g g.unit_ty g.unit_ty
let valSynData = SynValInfo([[]], SynInfo.unnamedRetVal)
let id = ident ("cctor", m)
CheckForNonAbstractInterface ModuleOrMemberBinding tcref (ClassCtorMemberFlags SynMemberFlagsTrivia.Zero) id.idRange
let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [], [], (ClassCtorMemberFlags SynMemberFlagsTrivia.Zero), valSynData, id, false)
CheckForNonAbstractInterface ModuleOrMemberBinding tcref ClassCtorMemberFlags id.idRange
let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [], [], ClassCtorMemberFlags, valSynData, id, false)
let prelimValReprInfo = TranslateSynValInfo m (TcAttributes cenv env) valSynData
let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, cctorTy)
let valReprInfo = InferGenericArityFromTyScheme prelimTyschemeG prelimValReprInfo
Expand Down Expand Up @@ -323,7 +322,7 @@ type IncrClassReprInfo =
let tps, _, argInfos, _, _ = GetValReprTypeInCompiledForm g valReprInfo 0 v.Type v.Range

let valSynInfo = SynValInfo(argInfos |> List.mapSquared (fun (_, argInfo) -> SynArgInfo([], false, argInfo.Name)), SynInfo.unnamedRetVal)
let memberFlags = (if isStatic then StaticMemberFlags else NonVirtualMemberFlags) SynMemberFlagsTrivia.Zero SynMemberKind.Member
let memberFlags = (if isStatic then StaticMemberFlags else NonVirtualMemberFlags) SynMemberKind.Member
let id = mkSynId v.Range name
let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, false, [], [], memberFlags, valSynInfo, mkSynId v.Range name, true)

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1656,4 +1656,5 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form"
3546,parsExpectingPatternInTuple,"Expecting pattern"
3547,parsExpectedPatternAfterToken,"Expected a pattern after this point"
3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data."
3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration"
3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration"
3550,chkDuplicatedMethodParameter,"Duplicate parameter. The parameter '%s' has been used more that once in this method."
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceInterfaceStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ module InterfaceStubGenerator =
| None, Some binding -> walkBinding binding
| Some getBinding, Some setBinding -> walkBinding getBinding |> Option.orElseWith (fun () -> walkBinding setBinding)
| SynMemberDefn.NestedType (typeDef, _access, _range) -> walkSynTypeDefn typeDef
| SynMemberDefn.ValField (_field, _range) -> None
| SynMemberDefn.ValField _ -> None
| SynMemberDefn.LetBindings (bindings, _isStatic, _isRec, _range) -> List.tryPick walkBinding bindings
| SynMemberDefn.Open _
| SynMemberDefn.ImplicitCtor _
Expand Down
14 changes: 7 additions & 7 deletions src/Compiler/Service/ServiceNavigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module NavigationImpl =
match fldspec with
| SynUnionCaseKind.Fields (flds) ->
flds
|> List.fold (fun st (SynField (_, _, _, _, _, _, _, m)) -> unionRangesChecked m st) range.Zero
|> List.fold (fun st (SynField (range = m)) -> unionRangesChecked m st) range.Zero
| SynUnionCaseKind.FullType (ty, _) -> ty.Range

let bodyRange mBody decls =
Expand Down Expand Up @@ -292,7 +292,7 @@ module NavigationImpl =
| SynTypeDefnSimpleRepr.Record (_, fields, mBody) ->
let fields =
[
for SynField (_, _, id, _, _, _, _, m) in fields do
for SynField (idOpt = id; range = m) in fields do
match id with
| Some ident -> yield createMember (ident, NavigationItemKind.Field, FSharpGlyph.Field, m, NavigationEntityKind.Record, false, access)
| _ -> ()
Expand Down Expand Up @@ -328,7 +328,7 @@ module NavigationImpl =
| SynMemberDefn.GetSetMember (Some bind, None, _, _)
| SynMemberDefn.GetSetMember (None, Some bind, _, _)
| SynMemberDefn.Member (bind, _) -> processBinding true enclosingEntityKind false bind
| SynMemberDefn.ValField (SynField (_, _, Some (rcid), _, _, _, access, range), _) ->
| SynMemberDefn.ValField(fieldInfo = SynField (idOpt = Some rcid; accessibility = access; range = range)) ->
[
createMember (rcid, NavigationItemKind.Field, FSharpGlyph.Field, range, enclosingEntityKind, false, access)
]
Expand Down Expand Up @@ -534,7 +534,7 @@ module NavigationImpl =
| SynTypeDefnSimpleRepr.Record (_, fields, mBody) ->
let fields =
[
for SynField (_, _, id, _, _, _, _, m) in fields do
for SynField (idOpt = id; range = m) in fields do
match id with
| Some ident -> yield createMember (ident, NavigationItemKind.Field, FSharpGlyph.Field, m, NavigationEntityKind.Record, false, access)
| _ -> ()
Expand All @@ -559,7 +559,7 @@ module NavigationImpl =
match memb with
| SynMemberSig.Member (SynValSig.SynValSig (ident = SynIdent (id, _); accessibility = access; range = m), _, _) ->
createMember (id, NavigationItemKind.Method, FSharpGlyph.Method, m, NavigationEntityKind.Class, false, access)
| SynMemberSig.ValField (SynField (_, _, Some (rcid), ty, _, _, access, _), _) ->
| SynMemberSig.ValField (SynField (idOpt = Some rcid; fieldType = ty; accessibility = access), _) ->
createMember (rcid, NavigationItemKind.Field, FSharpGlyph.Field, ty.Range, NavigationEntityKind.Class, false, access)
| _ -> ()
]
Expand Down Expand Up @@ -767,7 +767,7 @@ module NavigateTo =
addIdent kind id isSig container

let addField synField isSig container =
let (SynField (_, _, id, _, _, _, _, _)) = synField
let (SynField (idOpt = id)) = synField

match id with
| Some id -> addIdent NavigableItemKind.Field id isSig container
Expand Down Expand Up @@ -993,7 +993,7 @@ module NavigateTo =
Option.iter (fun b -> addBinding b None container) getBinding
Option.iter (fun b -> addBinding b None container) setBinding
| SynMemberDefn.NestedType (typeDef, _, _) -> walkSynTypeDefn typeDef container
| SynMemberDefn.ValField (field, _) -> addField field false container
| SynMemberDefn.ValField (fieldInfo = field) -> addField field false container
| SynMemberDefn.LetBindings (bindings, _, _, _) ->
bindings
|> List.iter (fun binding -> addBinding binding (Some NavigableItemKind.Field) container)
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceParseTreeWalk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ module SyntaxTraversal =
|> pick x
| ok -> ok
| SynMemberDefn.Inherit (synType, _identOption, range) -> traverseInherit (synType, range)
| SynMemberDefn.ValField (_synField, _range) -> None
| SynMemberDefn.ValField _ -> None
| SynMemberDefn.NestedType (synTypeDefn, _synAccessOption, _range) -> traverseSynTypeDefn path synTypeDefn

and traverseSynMatchClause origPath mc =
Expand Down
Loading