Skip to content

"internal error in instantiate" when using a generic impl method #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jsternberg opened this issue Jan 29, 2012 · 2 comments
Closed

"internal error in instantiate" when using a generic impl method #1700

jsternberg opened this issue Jan 29, 2012 · 2 comments

Comments

@jsternberg
Copy link
Contributor

This problem is illustrated with the following code:

use std;
import std::io::*;

iface ninja_str {
fn to_str() -> str;
}

impl of ninja_str for str {
fn to_str() -> str { self }
}

impl of ninja_str for [str] {
fn to_str() -> str {
alt vec::len(self) {
0u { "" }
x {
vec::foldl(self[0], vec::slice(self, 1u, x)) {|iter, y|
iter + ", " + y
}
}
}
}
}

// this works fine
fn print<T: ninja_str>(str: T) {
println(str.to_str());
}

impl ninja_file for writer {
// this causes 'error: internal error in instantiate'
fn build<T: ninja_str>(str: T) {
self.write(str::bytes(str.to_str()));
}
}

fn main() {
print("hello, world");
}

@jsternberg
Copy link
Contributor Author

Here's the pastebin for more readable code:
http://pastebin.com/abiZ8fNC

@marijnh
Copy link
Contributor

marijnh commented Jan 29, 2012

(Use triple-backticks before and after code blocks to have github format it properly.)

The problem is that typeck::dict::resolve_expr should also handle the cases of method_param and method_iface for expr_field. It's probably an easy fix. I'll look into it tomorrow.

@ghost ghost assigned marijnh Jan 29, 2012
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants