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

Commit5f122c3

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Do not infer record fields if the LRH type is already known (#3584)
* do not infer record fields if the LRH type is already known* update tests* fix ResolveExprDotLongIdent* Revert "update tests"This reverts commit 03dcb7ba24f64e0ff571027d76b6b186473ec8c0.* add a test and code style
1 parent6c6de72 commit5f122c3

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,30 +3123,33 @@ let private ResolveExprDotLongIdent (ncenv:NameResolver) m ad nenv typ lid findF
31233123
lettypeNameResInfo= TypeNameResolutionInfo.Default
31243124
letadhoctDotSearchAccessible= AtMostOneResult m(ResolveLongIdentInTypePrim ncenv nenv LookupKind.Expr ResolutionInfo.Empty1 m ad lid findFlag typeNameResInfo typ)
31253125
match adhoctDotSearchAccessiblewith
3126-
| Exception_->
3126+
| Exception_->
31273127
// If the dot is not resolved by adhoc overloading then look for a record field
31283128
// that can resolve the name.
3129-
letdotFieldIdSearch=
3130-
match lidwith
3131-
// A unique record label access, e.g expr.field
3132-
| id::restwhen nenv.eFieldLabels.ContainsKey(id.idText)->
3133-
match nenv.eFieldLabels.[id.idText]with
3134-
|[]-> NoResultsOrUsefulErrors
3135-
| rfref::_->
3136-
// NOTE (instantiationGenerator cleanup): we need to freshen here because we don't know the type.
3137-
// But perhaps the caller should freshen??
3138-
letitem= FreshenRecdFieldRef ncenv m rfref
3139-
OneSuccess(ResolutionInfo.Empty,item,rest)
3140-
|_-> NoResultsOrUsefulErrors
3129+
letdotFieldIdSearch=
3130+
// If the type is already known, we should not try to lookup a record field
3131+
if isAppTy ncenv.g typthen
3132+
NoResultsOrUsefulErrors
3133+
else
3134+
match lidwith
3135+
// A unique record label access, e.g expr.field
3136+
| id::restwhen nenv.eFieldLabels.ContainsKey(id.idText)->
3137+
match nenv.eFieldLabels.[id.idText]with
3138+
|[]-> NoResultsOrUsefulErrors
3139+
| rfref::_->
3140+
// NOTE (instantiationGenerator cleanup): we need to freshen here because we don't know the type.
3141+
// But perhaps the caller should freshen??
3142+
letitem= FreshenRecdFieldRef ncenv m rfref
3143+
OneSuccess(ResolutionInfo.Empty,item,rest)
3144+
|_-> NoResultsOrUsefulErrors
31413145

31423146
letsearch= dotFieldIdSearch
31433147
match AtMostOneResult m searchwith
31443148
| Result_as res-> ForceRaise res
31453149
|_->
31463150
letadhocDotSearchAll= ResolveLongIdentInTypePrim ncenv nenv LookupKind.Expr ResolutionInfo.Empty1 m AccessibleFromSomeFSharpCode lid findFlag typeNameResInfo typ
31473151
ForceRaise(AtMostOneResult m(search+++ adhocDotSearchAll))
3148-
3149-
| Result_->
3152+
|_->
31503153
ForceRaise adhoctDotSearchAccessible
31513154

31523155
letComputeItemRange wholem(lid:Ident list)rest=

‎tests/fsharp/tests.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,9 @@ module TypecheckTests =
21542154
letcfg={ cfgwith fsc_flags= cfg.fsc_flags+" --warnon:3218"}
21552155
singleNegTest cfg"neg100"
21562156

2157+
[<Test>]
2158+
let``type check neg101``()= singleNegTest(testConfig"typecheck/sigs")"neg101"
2159+
21572160
[<Test>]
21582161
let``type check neg_byref_1``()= singleNegTest(testConfig"typecheck/sigs")"neg_byref_1"
21592162

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
neg101.fs(7,11,7,14): typecheck error FS0039: The field, constructoror member 'Foo' isnot defined.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
moduleM
3+
4+
typeMyRec={ Foo:string}
5+
6+
letx:int=1
7+
lety= x.Foo
8+
letf1 z= z.Foo
9+
letf2(z:MyRec)= z.Foo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp