Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AssemblyScript/assemblyscript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.27.20
Choose a base ref
...
head repository: AssemblyScript/assemblyscript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.27.21
Choose a head ref
  • 1 commit
  • 3 files changed
  • 2 contributors

Commits on Nov 21, 2023

  1. fix: diagnose when accessing setter only property (#2800)

    Co-authored-by: CountBleck <Mr.YouKnowWhoIAm@protonmail.com>
    HerrCai0907 and CountBleck authored Nov 21, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    153def6 View commit details
Showing with 18 additions and 2 deletions.
  1. +12 −1 src/resolver.ts
  2. +1 −0 tests/compiler/getter-setter-errors.json
  3. +5 −1 tests/compiler/getter-setter-errors.ts
13 changes: 12 additions & 1 deletion src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1363,7 +1363,18 @@ export class Resolver extends DiagnosticEmitter {
}
case ElementKind.Property: { // someInstance.prop
let propertyInstance = <Property>target;
let getterInstance = assert(propertyInstance.getterInstance); // must have a getter
let getterInstance = propertyInstance.getterInstance;
if (!getterInstance) {
// In TS, getters without setters return `undefined`. Since AS doesn't have
// undefined, we instead diagnose it at compile time, but this isn't
// compatible with TS.
let setterInstance = assert(propertyInstance.setterInstance);
this.errorRelated(
DiagnosticCode.Property_0_only_has_a_setter_and_is_missing_a_getter,
targetNode.range, setterInstance.declaration.range, propertyInstance.name
);
return null;
}
let type = getterInstance.signature.returnType;
let classReference = type.getClassOrWrapper(this.program);
if (!classReference) {
1 change: 1 addition & 0 deletions tests/compiler/getter-setter-errors.json
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
"asc_flags": [
],
"stderr": [
"AS229: Property 'm' only has a setter and is missing a getter.",
"TS2808: Get accessor 'm2' must be at least as accessible as the setter.",
"EOF"
]
6 changes: 5 additions & 1 deletion tests/compiler/getter-setter-errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class UseNonExistedGetter {
set m(v: string) {}
}
new UseNonExistedGetter().m.toString();

class GetSetWithoutDifferenceVisibility {
public get m1(): i32 {
return 1;
@@ -9,7 +14,6 @@ class GetSetWithoutDifferenceVisibility {
}
public set m2(v: i32) {}
}

new GetSetWithoutDifferenceVisibility().m1; // m1 is valid
new GetSetWithoutDifferenceVisibility().m2; // m2 is invalid