Skip to content
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

expected 'T' but found 'T' #13488

Closed
Slowhand5 opened this issue Apr 13, 2014 · 1 comment
Closed

expected 'T' but found 'T' #13488

Slowhand5 opened this issue Apr 13, 2014 · 1 comment

Comments

@Slowhand5
Copy link

Newbie bug poster here.

rustc wire.rs
wire.rs:34:20: 34:26 error: mismatched types: expected `T` but found `T` (expected type parameter but found type parameter)
wire.rs:34         self.val = newVal;
                              ^~~~~~
error: aborting due to previous error
[jim@localhost rust_tests]$ rustc --version
rustc 0.10 (46867cc 2014-04-02 16:59:39 -0700)
host: i686-unknown-linux-gnu

===== testcase wire.rs follows =======

//use std::task;
//use std::comm;
extern crate  collections;

use std::io::timer::sleep;

//#[feature(managed_boxes)] 

//use collections::dlist::DList;

use collections::dlist::DList;


struct WListener < T > { 
    callback : 'static |T|
}

impl<T> WListener<T> { 
    fn call(&self, value : T) -> () { (self.callback)(value); } 
}


struct WMaster < T > { 
    name : & 'static str,
    val : T,
    listeners : DList<WListener<T>>
}

impl<T> WMaster<T> { 
    fn new<T>(iname : & 'static str, ival : T) -> WMaster<T> { 
        WMaster { name : iname, val : ival, listeners : DList::new() }
    } 
    fn assign<T>(&self, newVal : T) -> () { 
        self.val = newVal;
//        println!("{} is now {}", self.name, newVal);
    }

}

enum Wire <T> { 
    Master(~WMaster<T>),
    Ref(& 'static WMaster<T>)
} 


fn run_and(in1 : Receiver<bool>, 
           in2 : Receiver<bool>,
           zz : Sender<bool>) -> () 
{ 
  let mut ii1 : bool = false;
  let mut ii2 : bool = false;
  let mut prev_rr : bool = false;

  loop { 
    select! { 
      tt = in1.recv() => { ii1 = tt; },
      tt = in2.recv() => { ii2 = tt; }
      };     
      let rr = ii1 & ii2; 
      if rr != prev_rr { 
          prev_rr = rr;
          zz.send(rr);
      } 
   }      
}



fn top ()  -> ()  { 
   let (w1_s, w1_r) : (Sender<bool>, Receiver<bool>) = channel();
   let (w2_s, w2_r) : (Sender<bool>, Receiver<bool>) = channel();
   let (w3_s, w3_r) : (Sender<bool>, Receiver<bool>) = channel();
   let (w4_s, w4_r) : (Sender<bool>, Receiver<bool>) = channel();


   spawn(proc() { 
      loop { 
        let bb = w3_r.recv();
         println!("ww3 is now {}", bb);
     } 
   });
   spawn(proc() { 
      loop { 
        let bb = w4_r.recv();
         println!("ww4 is now {}", bb);
     } 
   });

   spawn(proc() { 
      run_and(w1_r, w2_r, w3_s);
   });

/*
   spawn(proc() { 
      run_and(w1_r2, w2_r2, w4_s);
   });
*/

   w1_s.send(true);
   sleep(1000);
   w2_s.send(true);
   sleep(1000);
   w1_s.send(true);
   sleep(1000);
   w2_s.send(true);
   sleep(1000);
   w1_s.send(false);
   sleep(1000);
   w2_s.send(false);
   sleep(1000);

   println!("I'm done now!");
}


fn main() { 
   top();
} 
@huonw
Copy link
Member

huonw commented Apr 13, 2014

Thanks for the report!

The problem here is you're redeclaring the variable <T> when you write fn new<T> and fn assign<T>, so that the T stored in self and that of newVal are different types.

This problem will be made more obvious if #11658 is fixed. (And so I'm closing as a dupe.)

(Also, btw, you can make code formatted more readable by using code blocks around them. e.g. I edited it to look like

```rust
//use std::task;
[...]
```

.)

@huonw huonw closed this as completed Apr 13, 2014
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