[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / typo-correction-recursive.cpp
blobb39beb5493f65ec39d74185c340eb0f11a81e190
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // Check the following typo correction behavior:
4 // - multiple typos in a single member call chain are all diagnosed
5 // - no typos are diagnosed for multiple typos in an expression when not all
6 // typos can be corrected
8 class DeepClass
10 public:
11 void trigger() const; // expected-note {{'trigger' declared here}}
14 class Y
16 public:
17 const DeepClass& getX() const { return m_deepInstance; } // expected-note {{'getX' declared here}}
18 private:
19 DeepClass m_deepInstance;
20 int m_n;
23 class Z
25 public:
26 const Y& getY0() const { return m_y0; } // expected-note {{'getY0' declared here}}
27 const Y& getActiveY() const { return m_y0; }
29 private:
30 Y m_y0;
31 Y m_y1;
34 Z z_obj;
36 void testMultipleCorrections()
38 z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'; did you mean 'getY0'}}
39 getM(). // expected-error {{no member named 'getM' in 'Y'; did you mean 'getX'}}
40 triggee(); // expected-error {{no member named 'triggee' in 'DeepClass'; did you mean 'trigger'}}
43 void testNoCorrections()
45 z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'}}
46 getM().
47 thisDoesntSeemToMakeSense();
50 struct C {};
51 struct D { int value; };
52 struct A {
53 C get_me_a_C();
55 struct B {
56 D get_me_a_D(); // expected-note {{'get_me_a_D' declared here}}
58 class Scope {
59 public:
60 A make_an_A();
61 B make_a_B(); // expected-note {{'make_a_B' declared here}}
64 Scope scope_obj;
66 int testDiscardedCorrections() {
67 return scope_obj.make_an_E(). // expected-error {{no member named 'make_an_E' in 'Scope'; did you mean 'make_a_B'}}
68 get_me_a_Z().value; // expected-error {{no member named 'get_me_a_Z' in 'B'; did you mean 'get_me_a_D'}}
71 class AmbiguousHelper {
72 public:
73 int helpMe();
74 int helpBe();
76 class Ambiguous {
77 public:
78 int calculateA();
79 int calculateB();
81 AmbiguousHelper getHelp1();
82 AmbiguousHelper getHelp2();
85 Ambiguous ambiguous_obj;
87 int testDirectAmbiguousCorrection() {
88 return ambiguous_obj.calculateZ(); // expected-error {{no member named 'calculateZ' in 'Ambiguous'}}
91 int testRecursiveAmbiguousCorrection() {
92 return ambiguous_obj.getHelp3(). // expected-error {{no member named 'getHelp3' in 'Ambiguous'}}
93 helpCe();
97 class DeepAmbiguityHelper {
98 public:
99 DeepAmbiguityHelper& help1();
100 DeepAmbiguityHelper& help2();
102 DeepAmbiguityHelper& methodA();
103 DeepAmbiguityHelper& somethingMethodB();
104 DeepAmbiguityHelper& functionC();
105 DeepAmbiguityHelper& deepMethodD();
106 DeepAmbiguityHelper& asDeepAsItGets();
109 DeepAmbiguityHelper deep_obj;
111 int testDeepAmbiguity() {
112 deep_obj.
113 methodB(). // expected-error {{no member named 'methodB' in 'DeepAmbiguityHelper'}}
114 somethingMethodC().
115 functionD().
116 deepMethodD().
117 help3().
118 asDeepASItGet().
119 functionE();
122 struct Dog {
123 int age; //expected-note{{'age' declared here}}
124 int size; //expected-note{{'size' declared here}}
127 int from_dog_years(int DogYears, int DogSize);
128 int get_dog_years() {
129 struct Dog doggo;
130 return from_dog_years(doggo.agee, //expected-error{{no member named 'agee' in 'Dog'; did you mean 'age'}}
131 doggo.sizee); //expected-error{{no member named 'sizee' in 'Dog'; did you mean 'size'}}