Skip to content

Commit fd272a5

Browse files
committed
Add type checker test case for access modifiers
1 parent 43ecc58 commit fd272a5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/types/checker/__tests__/classes.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { check } from '..'
22
import { parse } from '../../ast'
3-
import { CyclicInheritanceError } from '../../errors'
3+
import { CannotFindSymbolError, CyclicInheritanceError } from '../../errors'
44
import { Type } from '../../types/type'
55

66
const testcases: {
@@ -134,6 +134,23 @@ const testcases: {
134134
}
135135
`,
136136
result: { type: null, errors: [] }
137+
},
138+
{
139+
input: `
140+
class AccessControl {
141+
private void privateMethod() { System.out.println("Private method."); }
142+
public void attemptAccess() { privateMethod(); }
143+
}
144+
145+
public class Main {
146+
public static void main(String[] args) {
147+
AccessControl obj = new AccessControl();
148+
obj.attemptAccess();
149+
obj.privateMethod(); // Should be flagged as an error
150+
}
151+
}
152+
`,
153+
result: { type: null, errors: [new CannotFindSymbolError()] }
137154
}
138155
]
139156

0 commit comments

Comments
 (0)