Skip to content

Commit

Permalink
fix import relative path (#271)
Browse files Browse the repository at this point in the history
* fix import relative path

* bump to 0.7.6
  • Loading branch information
chenyan-dfinity authored Aug 20, 2021
1 parent 7eda836 commit 67e1e60
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid"
version = "0.7.5"
version = "0.7.6"
edition = "2018"
authors = ["DFINITY Team"]
description = "Candid is an interface description language (IDL) for interacting with canisters running on the Internet Computer."
Expand Down
4 changes: 4 additions & 0 deletions rust/candid/src/parser/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ fn check_file_(file: &Path, is_pretty: bool) -> Result<(TypeEnv, Option<Type>)>
file.parent().unwrap().to_path_buf()
} else {
std::env::current_dir()?
.join(file)
.parent()
.unwrap()
.to_path_buf()
};
let prog = std::fs::read_to_string(&file)
.map_err(|_| Error::msg(format!("Cannot open {:?}", file)))?;
Expand Down
3 changes: 3 additions & 0 deletions rust/candid/tests/assets/example.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "recursion.did";
import "import/a.did";
import "import/b/b.did";
type my_type = principal;
type List = opt record { head: int; tail: List };
type f = func (List, func (int32) -> (int64)) -> (opt List);
Expand All @@ -13,5 +15,6 @@ service server : {
g : (my_type, List, opt List, nested) -> (int, broker) query;
h : (vec opt text, variant { A: nat; B: opt text }, opt List) -> (record { id: nat; 0x2a: record {} });
i : f;
x : (a,b) -> (opt a, opt b);
}

2 changes: 2 additions & 0 deletions rust/candid/tests/assets/import/a.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "b/b.did";
type a = variant {a;b:b};
1 change: 1 addition & 0 deletions rust/candid/tests/assets/import/b/b.did
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type b = record { int;nat };
4 changes: 4 additions & 0 deletions rust/candid/tests/assets/ok/example.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Principal } from '@dfinity/principal';
export type A = B;
export type B = [] | [A];
export type List = [] | [{ 'head' : bigint, 'tail' : List }];
export type a = { 'a' : null } |
{ 'b' : b };
export type b = [bigint, bigint];
export interface broker { 'find' : (arg_0: string) => Promise<Principal> }
export type f = (arg_0: List, arg_1: [Principal, string]) => Promise<
[] | [List]
Expand Down Expand Up @@ -48,4 +51,5 @@ export interface _SERVICE {
arg_2: [] | [List],
) => Promise<{ _42_ : {}, 'id' : bigint }>,
'i' : f,
'x' : (arg_0: a, arg_1: b) => Promise<[[] | [a], [] | [b]]>,
}
3 changes: 3 additions & 0 deletions rust/candid/tests/assets/ok/example.did
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type A = B;
type B = opt A;
type List = opt record { head : int; tail : List };
type a = variant { a; b : b };
type b = record { int; nat };
type broker = service {
find : (text) -> (service { current : () -> (nat32); up : () -> () });
};
Expand Down Expand Up @@ -31,4 +33,5 @@ service : {
record { 42 : record {}; id : nat },
);
i : f;
x : (a, b) -> (opt a, opt b);
}
3 changes: 3 additions & 0 deletions rust/candid/tests/assets/ok/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const idlFactory = ({ IDL }) => {
[IDL.Opt(List)],
[],
);
const b = IDL.Tuple(IDL.Int, IDL.Nat);
const a = IDL.Variant({ 'a' : IDL.Null, 'b' : b });
return IDL.Service({
'f' : IDL.Func(
[list, IDL.Vec(IDL.Nat8), IDL.Opt(IDL.Bool)],
Expand All @@ -57,6 +59,7 @@ export const idlFactory = ({ IDL }) => {
[],
),
'i' : f,
'x' : IDL.Func([a, b], [IDL.Opt(a), IDL.Opt(b)], []),
});
};
export const init = ({ IDL }) => { return []; };
3 changes: 3 additions & 0 deletions rust/candid/tests/assets/ok/example.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module {
public type A = B;
public type B = ?A;
public type List = ?{ head : Int; tail : List };
public type a = { #a; #b : b };
public type b = (Int, Nat);
public type broker = actor {
find : shared Text -> async actor {
current : shared () -> async Nat32;
Expand Down Expand Up @@ -39,5 +41,6 @@ module {
id : Nat;
};
i : f;
x : shared (a, b) -> async (?a, ?b);
}
}

0 comments on commit 67e1e60

Please sign in to comment.