Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5a59397

Browse files
committedNov 15, 2023
fix: diagnose when accessing setter only property
1 parent 4f15024 commit 5a59397

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎src/resolver.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,15 @@ export class Resolver extends DiagnosticEmitter {
13631363
}
13641364
case ElementKind.Property: { // someInstance.prop
13651365
let propertyInstance = <Property>target;
1366-
let getterInstance = assert(propertyInstance.getterInstance); // must have a getter
1366+
let getterInstance = propertyInstance.getterInstance;
1367+
if (!getterInstance) {
1368+
let setterInstance = propertyInstance.setterInstance!;
1369+
this.errorRelated(
1370+
DiagnosticCode.Property_0_only_has_a_setter_and_is_missing_a_getter,
1371+
targetNode.range, setterInstance.declaration.range, propertyInstance.name
1372+
)
1373+
return null;
1374+
}
13671375
let type = getterInstance.signature.returnType;
13681376
let classReference = type.getClassOrWrapper(this.program);
13691377
if (!classReference) {
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"asc_flags": [
3+
],
4+
"stderr": [
5+
"AS229: Property 'm' only has a setter and is missing a getter."
6+
]
7+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class A {
2+
set m(v: string) {}
3+
}
4+
5+
changetype<A>(0).m.toString();

0 commit comments

Comments
 (0)
Please sign in to comment.