Skip to content

Commit

Permalink
Pick up backing classes of basic types in more locations (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenwang1996 authored and dcodeIO committed Jun 22, 2019
1 parent 726e45c commit 5a8eee0
Show file tree
Hide file tree
Showing 6 changed files with 2,704 additions and 6 deletions.
1 change: 1 addition & 0 deletions NOTICE
Expand Up @@ -14,6 +14,7 @@ under the licensing terms detailed in LICENSE:
* Nidin Vinayakan <01@01alchemist.com>
* Aaron Turner <aaron@aaronthedev.com>
* Willem Wyndham <willem@cs.umd.edu>
* Bowen Wang <bowen@nearprotocol.com>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
26 changes: 20 additions & 6 deletions src/resolver.ts
Expand Up @@ -748,14 +748,22 @@ export class Resolver extends DiagnosticEmitter {
return null;
}
let arrayType = indexedGet.signature.returnType;

// }
if (!(target = arrayType.classReference)) {
this.error(
DiagnosticCode.Property_0_does_not_exist_on_type_1,
propertyAccess.property.range, propertyName, arrayType.toString()
);
return null;
let classReference = arrayType.classReference;
if (!classReference) {
let typeClasses = this.program.typeClasses;
if (!arrayType.is(TypeFlags.REFERENCE) && typeClasses.has(arrayType.kind)) {
classReference = typeClasses.get(arrayType.kind)!;
} else {
this.error(
DiagnosticCode.Property_0_does_not_exist_on_type_1,
propertyAccess.property.range, propertyName, arrayType.toString()
);
return null;
}
}
target = classReference;
}
break;
}
Expand Down Expand Up @@ -1333,6 +1341,7 @@ export class Resolver extends DiagnosticEmitter {
contextualType,
reportMode
);

if (!target) return null;
if (target.kind == ElementKind.FUNCTION_PROTOTYPE) {
// `unchecked(expr: *): *` is special
Expand Down Expand Up @@ -1365,6 +1374,11 @@ export class Resolver extends DiagnosticEmitter {
// reuse resolvedThisExpression (might be property access)
// reuse resolvedElementExpression (might be element access)
return functionTarget;
} else {
let typeClasses = this.program.typeClasses;
if (!returnType.is(TypeFlags.REFERENCE) && typeClasses.has(returnType.kind)) {
return typeClasses.get(returnType.kind);
}
}
}
if (reportMode == ReportMode.REPORT) {
Expand Down
5 changes: 5 additions & 0 deletions tests/compiler/resolve-access.json
@@ -0,0 +1,5 @@
{
"asc_flags": [
"--runtime none"
]
}

0 comments on commit 5a8eee0

Please sign in to comment.