algorandfoundation / TEALScript

A subset of TypeScript for developing Algorand Smart Contracts. Enables ASC development with native TypeScript syntax, tooling, and IDE support

Home Page:https://tealscript.algo.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing return type on method leads to tough error message

barnjamin opened this issue · comments

we should provide a better error message for this. Can it be enforced with typecheck in editor? or just default to void if nothing provided?

TypeError: Can't compile the source code at src/contract.ts:7:4
> doit(x: Account, y: Asset){
>         assert(this.txn.sender == x)
>     }     Cannot read properties of undefined (reading 'typeAnnotation')
    at Compiler.processMethodDefinition (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:623:94)
    at Compiler.processNode (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:648:42)
    at /home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:633:41
    at Array.forEach (<anonymous>)
    at Compiler.processClassBody (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:633:19)
    at Compiler.processNode (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:648:42)
    at Compiler.processClassDeclaration (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:636:14)
    at Compiler.processNode (/home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:648:42)
    at /home/ben/tscript/node_modules/@joe-p/tealscript/dist/lib/compiler.js:338:26
    at Array.forEach (<anonymous>)

Yeah definitely need a better error here. I lean towards making a type annotation required (rather than defaulting to void) because TypeScript will automatically try to infer types, however we want explicit annotations to form the ABI method signature. I suppose TEALScript could also infer the type, but I like the explicit annotation a bit better.