Skip to content
Permalink
Browse files

Fix scoping for functions` type variables

  • Loading branch information...
tadeuzagallo committed Jul 18, 2016
1 parent 947186e commit 5f735b28221542a70af676d832abb1cb68015ad5
@@ -346,7 +346,7 @@ Type *Interface::typeof(EnvPtr env) {

s_interface = interface;
for (const auto &fn : functions) {
env->create(fn->getName()).type = fn->typeof(this->env);
env->create(fn->getName()).type = fn->typeof(this->env->create());
}
s_interface = nullptr;

@@ -413,20 +413,17 @@ Type *FunctionType::typeof(EnvPtr env) {
auto t = new TypeFunction();
t->generics = generics;

// isolate generics in a new env
auto newEnv = env->create();

for (auto &g : t->generics) {
g = uniqueName(g, newEnv);
g = uniqueName(g, env);
}

loadGenerics(t->generics, newEnv);
loadGenerics(t->generics, env);

for (auto p : params) {
t->types.push_back(p->typeof(newEnv));
t->types.push_back(p->typeof(env));
}
t->interface = s_interface;
t->returnType = returnType->typeof(newEnv);
t->returnType = returnType->typeof(env);
return t;
}

@@ -0,0 +1,4 @@
Type Error: Unknown type: `u`
On file `tests/errors/fn_generic_scoping.vrv` at 3:13
3: virtual y(u) -> t
^
@@ -0,0 +1,4 @@
interface f<t> {
virtual x<u>(u) -> t
virtual y(u) -> t
}
No changes.
@@ -0,0 +1,3 @@
fn f<t>(a: t) -> (t) -> void {
fn _(b: t) -> void { }
}

0 comments on commit 5f735b2

Please sign in to comment.
You can’t perform that action at this time.