typo-correction-recursive.cpp
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// RUN: %clang_cc1 -fsyntax-only -verify %s
// Check the following typo correction behavior:
// - multiple typos in a single member call chain are all diagnosed
// - no typos are diagnosed for multiple typos in an expression when not all
// typos can be corrected
class DeepClass
{
public:
void trigger() const; // expected-note {{'trigger' declared here}}
};
class Y
{
public:
const DeepClass& getX() const { return m_deepInstance; } // expected-note {{'getX' declared here}}
private:
DeepClass m_deepInstance;
int m_n;
};
class Z
{
public:
const Y& getY0() const { return m_y0; } // expected-note {{'getY0' declared here}}
const Y& getActiveY() const { return m_y0; }
private:
Y m_y0;
Y m_y1;
};
Z z_obj;
void testMultipleCorrections()
{
z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'; did you mean 'getY0'}}
getM(). // expected-error {{no member named 'getM' in 'Y'; did you mean 'getX'}}
triggee(); // expected-error {{no member named 'triggee' in 'DeepClass'; did you mean 'trigger'}}
}
void testNoCorrections()
{
z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'}}
getM().
thisDoesntSeemToMakeSense();
}
struct C {};
struct D { int value; };
struct A {
C get_me_a_C();
};
struct B {
D get_me_a_D(); // expected-note {{'get_me_a_D' declared here}}
};
class Scope {
public:
A make_an_A();
B make_a_B(); // expected-note {{'make_a_B' declared here}}
};
Scope scope_obj;
int testDiscardedCorrections() {
return scope_obj.make_an_E(). // expected-error {{no member named 'make_an_E' in 'Scope'; did you mean 'make_a_B'}}
get_me_a_Z().value; // expected-error {{no member named 'get_me_a_Z' in 'B'; did you mean 'get_me_a_D'}}
}
class AmbiguousHelper {
public:
int helpMe();
int helpBe();
};
class Ambiguous {
public:
int calculateA();
int calculateB();
AmbiguousHelper getHelp1();
AmbiguousHelper getHelp2();
};
Ambiguous ambiguous_obj;
int testDirectAmbiguousCorrection() {
return ambiguous_obj.calculateZ(); // expected-error {{no member named 'calculateZ' in 'Ambiguous'}}
}
int testRecursiveAmbiguousCorrection() {
return ambiguous_obj.getHelp3(). // expected-error {{no member named 'getHelp3' in 'Ambiguous'}}
helpCe();
}
class DeepAmbiguityHelper {
public:
DeepAmbiguityHelper& help1();
DeepAmbiguityHelper& help2();
DeepAmbiguityHelper& methodA();
DeepAmbiguityHelper& somethingMethodB();
DeepAmbiguityHelper& functionC();
DeepAmbiguityHelper& deepMethodD();
DeepAmbiguityHelper& asDeepAsItGets();
};
DeepAmbiguityHelper deep_obj;
int testDeepAmbiguity() {
deep_obj.
methodB(). // expected-error {{no member named 'methodB' in 'DeepAmbiguityHelper'}}
somethingMethodC().
functionD().
deepMethodD().
help3().
asDeepASItGet().
functionE();
}
struct Dog {
int age; //expected-note{{'age' declared here}}
int size; //expected-note{{'size' declared here}}
};
int from_dog_years(int DogYears, int DogSize);
int get_dog_years() {
struct Dog doggo;
return from_dog_years(doggo.agee, //expected-error{{no member named 'agee' in 'Dog'; did you mean 'age'}}
doggo.sizee); //expected-error{{no member named 'sizee' in 'Dog'; did you mean 'size'}}
}