Skip to content

Commit b38116a

Browse files
authored
Fixes: dotnet#14410 - Misleading error report on missing method (dotnet#14424)
* repro * Fix nested type error messages * remove comment * move testcase links
1 parent c31f11e commit b38116a

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

src/Compiler/Checking/NameResolution.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,7 @@ let rec ResolveLongIdentInTypePrim (ncenv: NameResolver) nenv lookupKind (resInf
26932693

26942694
match nestedSearchAccessible with
26952695
| Result res when not (isNil res) -> nestedSearchAccessible
2696+
| Exception _ -> nestedSearchAccessible
26962697
| _ ->
26972698
let suggestMembers (addToBuffer: string -> unit) =
26982699
for p in ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None LookupIsInstance.Ambivalent ad m ty do

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
<Compile Include="Language\ExtensionMethodTests.fs" />
179179
<Compile Include="ConstraintSolver\PrimitiveConstraints.fs" />
180180
<Compile Include="ConstraintSolver\MemberConstraints.fs" />
181+
<Compile Include="Interop\DeeplyNestedCSharpClasses.fs" />
181182
<Compile Include="Interop\SimpleInteropTests.fs" />
182183
<Compile Include="Interop\RequiredAndInitOnlyProperties.fs" />
183184
<Compile Include="Interop\StaticsInInterfaces.fs" />
@@ -214,6 +215,9 @@
214215
<Compile Include="FSharpChecker\CommonWorkflows.fs" />
215216
<Compile Include="FSharpChecker\SymbolUse.fs" />
216217
<Compile Include="FSharpChecker\FindReferences.fs" />
218+
</ItemGroup>
219+
220+
<ItemGroup>
217221
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
218222
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
219223
</None>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
namespace FSharp.Compiler.ComponentTests.Interop
3+
4+
open Xunit
5+
open FSharp.Test.Compiler
6+
open FSharp.Test
7+
open System
8+
9+
module ``Deeply nested CSharpClasses`` =
10+
11+
let cslib =
12+
CSharp """
13+
using System;
14+
15+
namespace MyNamespace
16+
{
17+
public class OuterClass
18+
{
19+
20+
public class InnerClass
21+
{
22+
23+
public class MoreInnerClass
24+
{
25+
public static void somefunction() { }
26+
}
27+
}
28+
}
29+
}"""
30+
31+
[<Fact>]
32+
let ``Missing type outerclass generates good message and range`` () =
33+
34+
let fsharpSource =
35+
"""
36+
let loss2 = MyNamespace.OoterClass.InnerClass.MoreInnerClass.somefunction() //Note the miss-typed functionname we expect a good error message
37+
"""
38+
FSharp fsharpSource
39+
|> asExe
40+
|> withReferences [cslib]
41+
|> compile
42+
|> withSingleDiagnostic (Error 39, Line 2, Col 25, Line 2, Col 35, "The value, constructor, namespace or type 'OoterClass' is not defined. Maybe you want one of the following:
43+
OuterClass")
44+
45+
[<Fact>]
46+
let ``Missing type nested type innerclass generates good message and range`` () =
47+
48+
let fsharpSource =
49+
"""
50+
let loss2 = MyNamespace.OuterClass.InerClass.MoreInnerClass.somefunction() //Note the miss-typed InnerClass name we expect a good error message
51+
"""
52+
FSharp fsharpSource
53+
|> asExe
54+
|> withReferences [cslib]
55+
|> compile
56+
|> shouldFail
57+
|> withSingleDiagnostic (Error 39, Line 2, Col 36, Line 2, Col 45, "The type 'OuterClass' does not define the field, constructor or member 'InerClass'.")
58+
59+
[<Fact>]
60+
let ``Missing type nested type moreinnerclass generates good message and range`` () =
61+
62+
let fsharpSource =
63+
"""
64+
let loss2 = MyNamespace.OuterClass.InnerClass.MoareInnerClass.somefunction() //Note the miss-typed MoreInnerClass we expect a good error message
65+
"""
66+
FSharp fsharpSource
67+
|> asExe
68+
|> withReferences [cslib]
69+
|> compile
70+
|> shouldFail
71+
|> withSingleDiagnostic (Error 39, Line 2, Col 47, Line 2, Col 62, "The type 'InnerClass' does not define the field, constructor or member 'MoareInnerClass'.")
72+
73+
[<Fact>]
74+
let ``Missing function generates good message and range`` () =
75+
76+
let fsharpSource =
77+
"""
78+
let loss2 = MyNamespace.OuterClass.InnerClass.MoreInnerClass.somefunctoion() //Note the miss-typed somefunction we expect a good error message
79+
"""
80+
FSharp fsharpSource
81+
|> asExe
82+
|> withReferences [cslib]
83+
|> compile
84+
|> shouldFail
85+
|> withSingleDiagnostic ((Error 39, Line 2, Col 62, Line 2, Col 75, """The type 'MoreInnerClass' does not define the field, constructor or member 'somefunctoion'. Maybe you want one of the following:
86+
somefunction"""))

0 commit comments

Comments
 (0)