Skip to content

Commit

Permalink
Address problem tighter to nameof usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 19, 2024
1 parent 86d06a2 commit a7c1228
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/Compiler/Driver/GraphChecking/FileContentMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,27 @@ let visitSynTypeConstraint (tc: SynTypeConstraint) : FileContentEntry list =
| SynTypeConstraint.WhereTyparIsEnum(typeArgs = typeArgs) -> List.collect visitSynType typeArgs
| SynTypeConstraint.WhereTyparIsDelegate(typeArgs = typeArgs) -> List.collect visitSynType typeArgs

/// Special case of `nameof Module` type of expression
let (|NameofExpr|_|) (e: SynExpr) =
let rec stripParen (e: SynExpr) =
match e with
| SynExpr.Paren(expr = expr) -> stripParen expr
| _ -> e

match e with
| SynExpr.App(flag = ExprAtomicFlag.NonAtomic; isInfix = false; funcExpr = SynExpr.Ident nameofIdent; argExpr = moduleNameExpr) ->
if nameofIdent.idText <> "nameof" then
None
else
match stripParen moduleNameExpr with
| SynExpr.Ident moduleNameIdent -> Some moduleNameIdent
| _ -> None
| _ -> None

let visitSynExpr (e: SynExpr) : FileContentEntry list =
let rec visit (e: SynExpr) (continuation: FileContentEntry list -> FileContentEntry list) : FileContentEntry list =
match e with
| NameofExpr moduleNameIdent -> continuation [ visitIdentAsPotentialModuleName moduleNameIdent ]

Check failure on line 325 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L325

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(325,56): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 325 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Source-Build (Managed))

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L325

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(325,56): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 325 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L325

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(325,56): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 325 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L325

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(325,56): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 325 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L325

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(325,56): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev
| SynExpr.Const _ -> continuation []
| SynExpr.Paren(expr = expr) -> visit expr continuation
| SynExpr.Quote(operator = operator; quotedExpr = quotedExpr) ->
Expand Down Expand Up @@ -389,7 +407,7 @@ let visitSynExpr (e: SynExpr) : FileContentEntry list =
| SynExpr.IfThenElse(ifExpr = ifExpr; thenExpr = thenExpr; elseExpr = elseExpr) ->
let continuations = List.map visit (ifExpr :: thenExpr :: Option.toList elseExpr)
Continuation.concatenate continuations continuation
| SynExpr.Typar _ -> continuation []
| SynExpr.Typar _
| SynExpr.Ident _ -> continuation []
| SynExpr.LongIdent(longDotId = longDotId) -> continuation (visitSynLongIdent longDotId)
| SynExpr.LongIdentSet(longDotId, expr, _) -> visit expr (fun nodes -> visitSynLongIdent longDotId @ nodes |> continuation)
Expand Down Expand Up @@ -517,9 +535,32 @@ let visitSynExpr (e: SynExpr) : FileContentEntry list =

visit e id

/// Special case of `| nameof Module ->` type of pattern
let (|NameofPat|_|) (pat: SynPat) =
let rec stripPats p =
match p with
| SynPat.Paren(pat = pat) -> stripPats pat
| _ -> p

match pat with
| SynPat.LongIdent(longDotId = SynLongIdent(id = [ nameofIdent ]); typarDecls = None; argPats = SynArgPats.Pats [ moduleNamePat ]) ->
if nameofIdent.idText <> "nameof" then
None
else
match stripPats moduleNamePat with
| SynPat.LongIdent(
longDotId = SynLongIdent.SynLongIdent(id = [ moduleNameIdent ]; dotRanges = []; trivia = [ None ])
extraId = None
typarDecls = None
argPats = SynArgPats.Pats []
accessibility = None) -> Some moduleNameIdent
| _ -> None
| _ -> None

let visitPat (p: SynPat) : FileContentEntry list =
let rec visit (p: SynPat) (continuation: FileContentEntry list -> FileContentEntry list) : FileContentEntry list =
match p with
| NameofPat moduleNameIdent -> continuation [ visitIdentAsPotentialModuleName moduleNameIdent ]

Check failure on line 563 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L563

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(563,55): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 563 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Source-Build (Managed))

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L563

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(563,55): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 563 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L563

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(563,55): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev

Check failure on line 563 in src/Compiler/Driver/GraphChecking/FileContentMapping.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

src/Compiler/Driver/GraphChecking/FileContentMapping.fs#L563

src/Compiler/Driver/GraphChecking/FileContentMapping.fs(563,55): error FS0039: The value or constructor 'visitIdentAsPotentialModuleName' is not defined. Maybe you want one of the following:� visitLongIdentForModuleAbbrev
| SynPat.Paren(pat = pat) -> visit pat continuation
| SynPat.Typed(pat = pat; targetType = t) -> visit pat (fun nodes -> nodes @ visitSynType t)
| SynPat.Const _ -> continuation []
Expand Down

0 comments on commit a7c1228

Please sign in to comment.