Skip to content

Commit 4e00653

Browse files
committed
try update mkSynMemberDefnGetSet
1 parent be13fe0 commit 4e00653

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,11 @@ let mkSynMemberDefnGetSet
354354
| None -> None
355355
| Some memberKind ->
356356

357-
// REVIEW: It's hard not to ignore the optPropertyType type annotation for 'set' properties. To apply it,
358-
// we should apply it to the last argument, but at this point we've already pushed the patterns that
359-
// make up the arguments onto the RHS. So we just always give a warning.
360-
361-
(match optPropertyType with
362-
| Some _ -> errorR (Error(FSComp.SR.parsTypeAnnotationsOnGetSet (), mBindLhs))
363-
| None -> ())
364-
357+
// Ensure we prioritize the explicit return type on the accessor if present
365358
let optReturnType =
366-
match (memberKind, optReturnType) with
367-
| SynMemberKind.PropertySet, _ -> optReturnType
368-
| _, None -> optPropertyType
369-
| _ -> optReturnType
370-
359+
match optReturnType with
360+
| Some _ -> optReturnType // Use accessor's explicit return type if provided
361+
| None -> optPropertyType // Otherwise fall back to property type
371362
// REDO with the correct member kind
372363
let binding =
373364
mkSynBinding
@@ -405,10 +396,6 @@ let mkSynMemberDefnGetSet
405396
| _ -> SynInfo.unnamedTopArg
406397

407398
match memberKind, valSynInfo, memFlags.IsInstance with
408-
| SynMemberKind.PropertyGet, SynValInfo([], _ret), false
409-
| SynMemberKind.PropertyGet, SynValInfo([ _ ], _ret), true ->
410-
raiseParseErrorAt mWholeBindLhs (FSComp.SR.parsGetterMustHaveAtLeastOneArgument ())
411-
412399
| SynMemberKind.PropertyGet, SynValInfo(thisArg :: indexOrUnitArgs :: rest, ret), true ->
413400
if not rest.IsEmpty then
414401
reportParseErrorAt mWholeBindLhs (FSComp.SR.parsGetterAtMostOneArgument ())
@@ -437,7 +424,10 @@ let mkSynMemberDefnGetSet
437424
reportParseErrorAt mWholeBindLhs (FSComp.SR.parsSetterAtMostTwoArguments ())
438425

439426
SynValInfo([ indexArgs @ adjustValueArg valueArg ], ret)
440-
427+
// For getters and setters with explicit return types or other patterns
428+
// that don't match earlier cases, use valInfo as is
429+
| SynMemberKind.PropertyGet, valInfo, _
430+
| SynMemberKind.PropertySet, valInfo, _ -> valInfo
441431
| _ ->
442432
// should be unreachable, cover just in case
443433
raiseParseErrorAt mWholeBindLhs (FSComp.SR.parsInvalidProperty ())

0 commit comments

Comments
 (0)