Skip to content

Commit

Permalink
upgrade the builtin func
Browse files Browse the repository at this point in the history
  • Loading branch information
peze authored and JacksonTian committed Jan 25, 2024
1 parent 28442ae commit 4480389
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions builtin/file.dara
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function read(size: number): bytes;

function write(data: bytes): void;

static async function createReadStream(path: string): readable;
static function createReadStream(path: string): readable;

static async function createWriteStream(path: string): writable;
static function createWriteStream(path: string): writable;

static async function exists(path: string): boolean;
4 changes: 2 additions & 2 deletions builtin/string.dara
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
init(data: string){}

function split(sep: string, limit: number): [ string ];
function split(sep: string): [ string ];

function replace(oldStr: string, newStr: string, count: integer): string;
function replace(regexStr: string, newStr: string): string;

function contains(substr: string): boolean;

Expand Down
5 changes: 4 additions & 1 deletion lib/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ class TypeChecker {
} else if (ast.type === 'null') {
// noop();
} else if (ast.type === 'group') {
// noop();
this.visitExpr(ast.expr, env);
} else if (ast.type === 'property_access') {
this.checkProperty(ast, env);
} else if (ast.type === 'object') {
Expand Down Expand Up @@ -2189,6 +2189,7 @@ class TypeChecker {
if (ast.left.type === 'static_or_instance_call') {
const id = ast.left.id;
this.checkId(id, env);

if (env.local.hasDefined(id.lexeme)) {
ast.left.type = 'instance_call';
this.visitInstanceCall(ast, env);
Expand Down Expand Up @@ -2226,8 +2227,10 @@ class TypeChecker {
moduleName = type.name;
if(isBasicType(type.type)) {
moduleName = this.getBuiltinModule(type.type);
ast.builtinModule = moduleName;
} else if(type.type === 'basic' && isBasicType(type.name)) {
moduleName = this.getBuiltinModule(type.name);
ast.builtinModule = moduleName;
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/builtin_module/string.dara
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
static async function main(args: [string]): void {
var fullStr = args.join(',');
args = fullStr.split(',', 10);
args = fullStr.split(',');

if((fullStr.length() > 0) && fullStr.contains('hangzhou')) {
var newStr1 = fullStr.replace('hangzhou', 'beijing', 1);
var newStr1 = fullStr.replace('/hangzhou/g', 'beijing');
}

if(fullStr.hasPrefix('cn')) {
var newStr2 = fullStr.replace('cn', 'zh', 1);
var newStr2 = fullStr.replace('/cn/gi', 'zh');
}

if(fullStr.hasPrefix('beijing')) {
var newStr3 = fullStr.replace('beijing', 'chengdu', -1);
var newStr3 = fullStr.replace('/beijing/', 'chengdu');
}

var start = fullStr.index('beijing');
Expand Down
2 changes: 1 addition & 1 deletion test/semantic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ describe('semantic', function () {
it('compare expr should ok', function () {
expect(function () {
parse(`static function callOSS(): boolean {
return (true == false) || ("string" >= "string") || (3 < 3) || ((3 <= 2) && (2 >= 3));
return (true == false) || ("string" == "string") || (3 < 3) || ((3 <= 2) && (2 >= 3));
}`, '__filename');
}).to.not.throwException();

Expand Down

0 comments on commit 4480389

Please sign in to comment.