Fix symbol resolution and error handling

This commit is contained in:
Sam Vervaeck 2020-05-27 20:59:45 +02:00
parent 05b024c3f4
commit ce8c0aa7a1
9 changed files with 36 additions and 35 deletions

View file

@ -120,7 +120,7 @@ node BoltLiftedTypeExpression > BoltTypeExpression {
node BoltTypeParameter {
index: usize,
name: BoltIdentifier,
typeNode: Option<BoltTypeExpression>,
typeExpr: Option<BoltTypeExpression>,
defaultType: Option<BoltTypeExpression>,
}
@ -131,7 +131,7 @@ node BoltBindPattern > BoltPattern {
}
node BoltTypePattern > BoltPattern {
type: BoltTypeExpression,
typeExpr: BoltTypeExpression,
nestedPattern: BoltPattern,
}
@ -246,7 +246,7 @@ node BoltExpressionStatement > BoltStatement {
node BoltParameter {
index: usize,
bindings: BoltPattern,
type: Option<BoltTypeExpression>,
typeExpr: Option<BoltTypeExpression>,
defaultValue: Option<BoltExpression>,
}
@ -280,7 +280,7 @@ node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration {
node BoltVariableDeclaration > BoltFunctionBodyElement, BoltDeclaration {
modifiers: BoltModifiers,
bindings: BoltPattern,
type: Option<BoltTypeExpression>,
typeExpr: Option<BoltTypeExpression>,
value: Option<BoltExpression>,
}
@ -335,7 +335,7 @@ node BoltRecordMember;
node BoltRecordField > BoltRecordMember {
name: BoltIdentifier,
type: BoltTypeExpression,
typeExpr: BoltTypeExpression,
}
node BoltRecordDeclaration > BoltDeclaration, BoltTypeDeclaration {

22
src/ast.d.ts vendored
View file

@ -1,5 +1,5 @@
import { Type } from "./checker"
import { Type } from "./types"
import { Package } from "./common"
import { TextSpan } from "./text"
@ -2941,7 +2941,7 @@ export interface BoltTypeParameter extends SyntaxBase {
kind: SyntaxKind.BoltTypeParameter;
index: number;
name: BoltIdentifier;
typeNode: BoltTypeExpression | null;
typeExpr: BoltTypeExpression | null;
defaultType: BoltTypeExpression | null;
parentNode: BoltTypeParameterParent;
getChildNodes(): IterableIterator<BoltTypeParameterChild>
@ -3020,7 +3020,7 @@ export type BoltBindPatternChild
export interface BoltTypePattern extends SyntaxBase {
kind: SyntaxKind.BoltTypePattern;
type: BoltTypeExpression;
typeExpr: BoltTypeExpression;
nestedPattern: BoltPattern;
parentNode: BoltTypePatternParent;
getChildNodes(): IterableIterator<BoltTypePatternChild>
@ -4250,7 +4250,7 @@ export interface BoltParameter extends SyntaxBase {
kind: SyntaxKind.BoltParameter;
index: number;
bindings: BoltPattern;
type: BoltTypeExpression | null;
typeExpr: BoltTypeExpression | null;
defaultValue: BoltExpression | null;
parentNode: BoltParameterParent;
getChildNodes(): IterableIterator<BoltParameterChild>
@ -4380,7 +4380,7 @@ export interface BoltVariableDeclaration extends SyntaxBase {
kind: SyntaxKind.BoltVariableDeclaration;
modifiers: BoltModifiers;
bindings: BoltPattern;
type: BoltTypeExpression | null;
typeExpr: BoltTypeExpression | null;
value: BoltExpression | null;
parentNode: BoltVariableDeclarationParent;
getChildNodes(): IterableIterator<BoltVariableDeclarationChild>
@ -4622,7 +4622,7 @@ export type BoltRecordMember
export interface BoltRecordField extends SyntaxBase {
kind: SyntaxKind.BoltRecordField;
name: BoltIdentifier;
type: BoltTypeExpression;
typeExpr: BoltTypeExpression;
parentNode: BoltRecordFieldParent;
getChildNodes(): IterableIterator<BoltRecordFieldChild>
}
@ -7884,9 +7884,9 @@ export function createBoltModulePath(isAbsolute: boolean, elements: BoltIdentifi
export function createBoltReferenceTypeExpression(name: BoltQualName, arguments: BoltTypeExpression[] | null, span?: TextSpan | null): BoltReferenceTypeExpression;
export function createBoltFunctionTypeExpression(params: BoltParameter[], returnType: BoltTypeExpression | null, span?: TextSpan | null): BoltFunctionTypeExpression;
export function createBoltLiftedTypeExpression(expression: BoltExpression, span?: TextSpan | null): BoltLiftedTypeExpression;
export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeNode: BoltTypeExpression | null, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter;
export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeExpr: BoltTypeExpression | null, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter;
export function createBoltBindPattern(name: BoltIdentifier, span?: TextSpan | null): BoltBindPattern;
export function createBoltTypePattern(type: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern;
export function createBoltTypePattern(typeExpr: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern;
export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null): BoltExpressionPattern;
export function createBoltTuplePatternElement(index: number, pattern: BoltPattern, span?: TextSpan | null): BoltTuplePatternElement;
export function createBoltTuplePattern(elements: BoltTuplePatternElement[], span?: TextSpan | null): BoltTuplePattern;
@ -7910,10 +7910,10 @@ export function createBoltConditionalCase(test: BoltExpression | null, body: Bol
export function createBoltConditionalStatement(cases: BoltConditionalCase[], span?: TextSpan | null): BoltConditionalStatement;
export function createBoltResumeStatement(value: BoltExpression, span?: TextSpan | null): BoltResumeStatement;
export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null): BoltExpressionStatement;
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
export function createBoltParameter(index: number, bindings: BoltPattern, typeExpr: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
export function createBoltModule(modifiers: BoltModifiers, name: BoltIdentifier[], elements: BoltSourceElement[], span?: TextSpan | null): BoltModule;
export function createBoltFunctionDeclaration(modifiers: BoltModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeExpression | null, typeParams: BoltTypeParameter[] | null, body: BoltFunctionBodyElement[], span?: TextSpan | null): BoltFunctionDeclaration;
export function createBoltVariableDeclaration(modifiers: BoltModifiers, bindings: BoltPattern, type: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
export function createBoltVariableDeclaration(modifiers: BoltModifiers, bindings: BoltPattern, typeExpr: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
export function createBoltPlainImportSymbol(remote: BoltQualName, local: BoltSymbol, span?: TextSpan | null): BoltPlainImportSymbol;
export function createBoltImportDirective(modifiers: BoltModifiers, file: BoltStringLiteral, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDirective;
export function createBoltExportSymbol(span?: TextSpan | null): BoltExportSymbol;
@ -7922,7 +7922,7 @@ export function createBoltExportDirective(file: string, symbols: BoltExportSymbo
export function createBoltTraitDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltTraitDeclaration;
export function createBoltImplDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, trait: BoltTypeExpression, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltImplDeclaration;
export function createBoltTypeAliasDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltTypeAliasDeclaration;
export function createBoltRecordField(name: BoltIdentifier, type: BoltTypeExpression, span?: TextSpan | null): BoltRecordField;
export function createBoltRecordField(name: BoltIdentifier, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltRecordField;
export function createBoltRecordDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParms: BoltTypeParameter[] | null, members: BoltRecordMember[] | null, span?: TextSpan | null): BoltRecordDeclaration;
export function createBoltMacroCall(name: BoltIdentifier, text: string, span?: TextSpan | null): BoltMacroCall;
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;

View file

@ -23,7 +23,7 @@ export class CheckInvalidFilePaths extends NodeVisitor {
const sourceFile = this.program.resolveToSourceFile(node.file.value, node);
if (sourceFile === null) {
this.diagnostics.add({
severity: 'error',
severity: 'fatal',
message: E_FILE_NOT_FOUND,
args: { filename: node.file.value },
node: node.file,
@ -62,7 +62,7 @@ export class CheckReferences extends NodeVisitor {
const sym = currScope!.getLocalSymbol(name.text);;
if (sym === null) {
failedToFindScope = true;
partiallyMatchingModules.push((currScope!.source) as NodeScopeSource).node);
partiallyMatchingModules.push(((currScope!.source) as NodeScopeSource).node);
break;
}
assert(every(sym.declarations.values(), decl => decl.kind === SyntaxKind.BoltModule));
@ -115,7 +115,7 @@ export class CheckReferences extends NodeVisitor {
}
protected visitBoltReferenceTypeExpression(node: BoltReferenceTypeExpression) {
const scope = this.resolver.getScopeForNode(node, ScopeType.Type);
const scope = this.resolver.getScopeSurroundingNode(node, ScopeType.Type);
assert(scope !== null);
const symbolPath = getSymbolPathFromNode(node.name);
const resolvedSym = this.resolver.resolveSymbolPath(symbolPath, scope!);

View file

@ -40,7 +40,8 @@ function firstIndexOfNonEmpty(str: string) {
export class DiagnosticPrinter {
public hasErrors = false;
public hasErrors = false
public hasFatal = false;
public add(diagnostic: Diagnostic): void {
@ -61,6 +62,9 @@ export class DiagnosticPrinter {
this.hasErrors = true;
out += chalk.bold.red('error: ');
break;
case 'fatal':
this.hasFatal = true;
out += chalk.bold.red('fatal:' );
case 'warning':
this.hasErrors = true;
out += chalk.bold.red('warning: ');

View file

@ -373,8 +373,8 @@ export class Parser {
const t1 = tokens.get();
assertToken(t1, SyntaxKind.BoltStringLiteral);
const symbols: BoltImportSymbol[] = [];
const t2 = tokens.get();
const symbols = null;
const t2 = tokens.peek();
if (t2.kind === SyntaxKind.BoltParenthesized) {
// TODO implement grammar and parsing logic for symbols
}

View file

@ -518,13 +518,7 @@ export class SymbolResolver {
// Once we've handled any module path that might have been present,
// we resolve the actual symbol using a helper method.
const sym = scope.getSymbol(path.name);
if (sym === null) {
return null;
}
return sym;
return scope.getSymbol(path.name);
}
}

View file

@ -1,6 +1,6 @@
import { Program } from "../program"
import { Container, Newable } from "../di"
import { Container, Newable } from "../ioc"
import {SourceFile} from "../ast";
export interface Transformer {

View file

@ -1,5 +1,5 @@
import { Type } from "./checker"
import { Type } from "./types"
import { Package } from "./common"
import { TextSpan } from "./text"

View file

@ -292,20 +292,23 @@ export class TypeChecker {
case SyntaxKind.BoltFunctionExpression:
{
const paramTypes = node.params.map(param => {
if (param.type === null) {
if (param.typeExpr === null) {
return this.anyType;
}
return this.createInitialTypeForTypeExpression(param.type);
return this.createInitialTypeForTypeExpression(param.typeExpr);
});
let returnType = node.returnType === null
? this.anyType
: this.createInitialTypeForTypeExpression(node.returnType);
const funcType = new FunctionType(paramTypes, returnType);
resultType = new FunctionType(paramTypes, returnType);
break;
}
case SyntaxKind.BoltQuoteExpression:
return this.syntaxType;
{
resultType = this.syntaxType;
break
}
case SyntaxKind.BoltMemberExpression:
case SyntaxKind.BoltReferenceExpression: