hdl.ast: tighten assertion in Switch().
This commit is contained in:
		
							parent
							
								
									6beba3a48b
								
							
						
					
					
						commit
						f1174655b1
					
				|  | @ -1022,12 +1022,12 @@ class Switch(Statement): | ||||||
|         for key, stmts in cases.items(): |         for key, stmts in cases.items(): | ||||||
|             if isinstance(key, (bool, int)): |             if isinstance(key, (bool, int)): | ||||||
|                 key = "{:0{}b}".format(key, len(self.test)) |                 key = "{:0{}b}".format(key, len(self.test)) | ||||||
|                 assert len(key) <= len(self.test) |  | ||||||
|             elif isinstance(key, str): |             elif isinstance(key, str): | ||||||
|                 assert len(key) == len(self.test) |                 pass | ||||||
|             else: |             else: | ||||||
|                 raise TypeError("Object '{!r}' cannot be used as a switch key" |                 raise TypeError("Object '{!r}' cannot be used as a switch key" | ||||||
|                                 .format(key)) |                                 .format(key)) | ||||||
|  |             assert len(key) == len(self.test) | ||||||
|             if not isinstance(stmts, Iterable): |             if not isinstance(stmts, Iterable): | ||||||
|                 stmts = [stmts] |                 stmts = [stmts] | ||||||
|             self.cases[key] = Statement.wrap(stmts) |             self.cases[key] = Statement.wrap(stmts) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 whitequark
						whitequark