Skip to content

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

Description

@jsternberg

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");
}

Activity

  1. jsternberg commented on Jan 29, 2012

    @jsternberg
    ContributorAuthor

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

  2. marijnh commented on Jan 29, 2012

    @marijnh
    Contributor

    (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.

  3. ghost assigned on Jan 29, 2012
  4. added 3 commits that reference this issue on Aug 21, 2026
  5. added a commit that references this issue on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions