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

Commitb48f924

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
TypeChecker notifies name resolution sink about IL constant fields (#3612)
* TypeChecker notifies name resolution sink about IL constant fields* TypeChecker notifies name resolution sink about literal values in patterns* add tests
1 parent907e113 commitb48f924

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,6 +5310,8 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
53105310
checkNoArgsForLiteral()
53115311
UnifyTypes cenv env m ty (finfo.FieldType(cenv.amap, m))
53125312
let c' = TcFieldInit m lit
5313+
let item = Item.ILField(finfo)
5314+
CallNameResolutionSink cenv.tcSink (m, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Pattern, env.DisplayEnv, env.AccessRights)
53135315
(fun _ -> TPat_const (c', m)), (tpenv, names, takenNames)
53145316

53155317
| Item.RecdField rfinfo ->
@@ -5337,6 +5339,8 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
53375339
CheckFSharpAttributes cenv.g vref.Attribs m |> CommitOperationResult
53385340
checkNoArgsForLiteral()
53395341
UnifyTypes cenv env m ty vexpty
5342+
let item = Item.Value(vref)
5343+
CallNameResolutionSink cenv.tcSink (m, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Pattern, env.DisplayEnv, env.AccessRights)
53405344
(fun _ -> TPat_const (lit, m)), (tpenv, names, takenNames)
53415345

53425346
| _ -> error (Error(FSComp.SR.tcRequireVarConstRecogOrLiteral(), m))

‎tests/service/EditorTests.fs‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,103 @@ let test3 = System.Text.RegularExpressions.RegexOptions.Compiled
613613
]
614614
|]
615615

616+
[<Test>]
617+
let``IL enum fields should be reported``()=
618+
letinput=
619+
"""
620+
open System
621+
622+
let _ =
623+
match ConsoleKey.Tab with
624+
| ConsoleKey.OemClear -> ConsoleKey.A
625+
| _ -> ConsoleKey.B
626+
"""
627+
628+
letfile="/home/user/Test.fsx"
629+
let_,typeCheckResults= parseAndCheckScript(file, input)
630+
typeCheckResults.GetAllUsesOfAllSymbolsInFile()
631+
|> Async.RunSynchronously
632+
|> Array.map(fun su->
633+
letr= su.RangeAlternate
634+
su.Symbol.ToString(),(r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
635+
|> shouldEqual
636+
[|("ConsoleKey",(5,10,5,20))
637+
("field Tab",(5,10,5,24))
638+
("ConsoleKey",(6,6,6,16))
639+
("field OemClear",(6,6,6,25))
640+
("ConsoleKey",(6,29,6,39))
641+
("field A",(6,29,6,41))
642+
("ConsoleKey",(7,11,7,21))
643+
("field B",(7,11,7,23))
644+
("Test",(1,0,1,0))|]
616645

646+
[<Test>]
647+
let``Literal values should be reported``()=
648+
letinput=
649+
"""
650+
module Module1 =
651+
let [<Literal>] ModuleValue = 1
652+
653+
let _ =
654+
match ModuleValue + 1 with
655+
| ModuleValue -> ModuleValue + 2
656+
| _ -> 0
657+
658+
type Class1() =
659+
let [<Literal>] ClassValue = 1
660+
static let [<Literal>] StaticClassValue = 2
661+
662+
let _ = ClassValue
663+
let _ = StaticClassValue
664+
665+
let _ =
666+
match ClassValue + StaticClassValue with
667+
| ClassValue -> ClassValue + 1
668+
| StaticClassValue -> StaticClassValue + 2
669+
| _ -> 3
670+
"""
671+
672+
letfile="/home/user/Test.fsx"
673+
let_,typeCheckResults= parseAndCheckScript(file, input)
674+
typeCheckResults.GetAllUsesOfAllSymbolsInFile()
675+
|> Async.RunSynchronously
676+
|> Array.map(fun su->
677+
letr= su.RangeAlternate
678+
su.Symbol.ToString(),(r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
679+
|> shouldEqual
680+
[|("LiteralAttribute",(3,10,3,17))
681+
("LiteralAttribute",(3,10,3,17))
682+
("member .ctor",(3,10,3,17))
683+
("val ModuleValue",(3,20,3,31))
684+
("val op_Addition",(6,26,6,27))
685+
("val ModuleValue",(6,14,6,25))
686+
("val ModuleValue",(7,10,7,21))
687+
("val op_Addition",(7,37,7,38))
688+
("val ModuleValue",(7,25,7,36))
689+
("Module1",(2,7,2,14))
690+
("Class1",(10,5,10,11))
691+
("member .ctor",(10,5,10,11))
692+
("LiteralAttribute",(11,10,11,17))
693+
("LiteralAttribute",(11,10,11,17))
694+
("member .ctor",(11,10,11,17))
695+
("val ClassValue",(11,20,11,30))
696+
("LiteralAttribute",(12,17,12,24))
697+
("LiteralAttribute",(12,17,12,24))
698+
("member .ctor",(12,17,12,24))
699+
("val StaticClassValue",(12,27,12,43))
700+
("val ClassValue",(14,12,14,22))
701+
("val StaticClassValue",(15,12,15,28))
702+
("val op_Addition",(18,25,18,26))
703+
("val ClassValue",(18,14,18,24))
704+
("val StaticClassValue",(18,27,18,43))
705+
("val ClassValue",(19,10,19,20))
706+
("val op_Addition",(19,35,19,36))
707+
("val ClassValue",(19,24,19,34))
708+
("val StaticClassValue",(20,10,20,26))
709+
("val op_Addition",(20,47,20,48))
710+
("val StaticClassValue",(20,30,20,46))
711+
("member .cctor",(10,5,10,11))
712+
("Test",(1,0,1,0))|]
617713

618714
//-------------------------------------------------------------------------------
619715

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp