how I can clear of error Function has override specified but does not override anything - solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "#openzeppelin/contracts/utils/math/SafeMath.sol";
contract MinterYT is ERC721,ERC721Enumerable,ERC721URIStorage{
using SafeMath for uint256;
uint public constant mintPrice=0;
function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override(ERC721,ERC721Enumerable)
{
super._beforeTokenTransfer(from,to,tokenId);
}
function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
returns(string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721,ERC721Enumerable)
returns(bool)
{
return super.supportsInterface(interfaceId);
}
constructor() ERC721("YTMinter","YTM"){}
function mint(string memory _uri) public payable
{
uint256 mintIndex=totalSupply();
_safeMint(msg.sender,mintIndex);
_setTokenURI(mintIndex, _uri);
}
}
the error was
TypeError: Function has override specified but does not override anything.
--> contracts/Mint.sol:13:85:
|
13 | function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override(ERC721,ERC721Enumerable)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Invalid contracts specified in override list: "ERC721" and "ERC721Enumerable".
--> contracts/Mint.sol:13:85:
|
13 | function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override(ERC721,ERC721Enumerable)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: This contract:
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:19:1:
|
19 | contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
| ^ (Relevant source part starts here and spans across multiple lines).
Note: This contract:
--> #openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol:14:1:
|
14 | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function visibility differs.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:321:5:
|
321 | function _burn(uint256 tokenId) internal virtual {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function return types differ.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:321:5:
|
321 | function _burn(uint256 tokenId) internal virtual {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function visibility differs.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:321:5:
|
321 | function _burn(uint256 tokenId) internal virtual {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function return types differ.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:321:5:
|
321 | function _burn(uint256 tokenId) internal virtual {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function visibility differs.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol:55:5:
|
55 | function _burn(uint256 tokenId) internal virtual override {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Overriding function return types differ.
--> contracts/Mint.sol:18:5:
|
18 | function _burn(uint256 tokenId) public view override(ERC721,ERC721URIStorage)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
--> #openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol:55:5:
|
55 | function _burn(uint256 tokenId) internal virtual override {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Derived contract must override function "_beforeTokenTransfer". Two or more base classes define function with same name and parameter types.
--> contracts/Mint.sol:9:1:
|
9 | contract MinterYT is ERC721,ERC721Enumerable,ERC721URIStorage{
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC721":
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:467:5:
|
467 | function _beforeTokenTransfer(
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC721Enumerable":
--> #openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol:60:5:
|
60 | function _beforeTokenTransfer(
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Derived contract must override function "tokenURI". Two or more base classes define function with same name and parameter types.
--> contracts/Mint.sol:9:1:
|
9 | contract MinterYT is ERC721,ERC721Enumerable,ERC721URIStorage{
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC721":
--> #openzeppelin/contracts/token/ERC721/ERC721.sol:93:5:
|
93 | function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC721URIStorage":
--> #openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol:20:5:
|
20 | function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Wrong argument count for function call: 3 arguments given but expected 4.
--> contracts/Mint.sol:15:1:
|
15 | super._beforeTokenTransfer(from,to,tokenId);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the result is image link was send metamask wallet in 0 eth

Related

Why do lines 14 and 21 not compile (for my Kotlin function)?

I have a function named collectCustomizerFunctions which should create a MutableList<KCallable<*>> of all the functions of a specified class and its sub-classes which are annotated with CustomizerFunction.
Recursively, customizerFuns (the MutableList<KCallable<*>>) should have all of the "cutomizer functions" added to it.
When I try to build my Gradle project, it fails with two exceptions:
e: collectCustomizerFuns.kt:14:33 Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.
e: collectCustomizerFuns.kt:21:30 Type mismatch: inferred type is Any but CapturedType(*) was expected
Here is my code:
3 | import kotlin.reflect.KClass
4 | import kotlin.reflect.KCallable
5 | import kotlin.reflect.full.allSuperclasses
6 |
7 | #Utility
8 | public tailrec fun <T: Any> collectCustomizerFuns(
9 | specClass: KClass<T>,
10 | customizerFuns: MutableList<KCallable<*>>
11 | ): Unit {
12 | // add annotated functions of this class
13 | for (member in specClass.members) {
14 | if (CustomizerFunction::class in member.annotations) { <--- ERROR
15 | customizerFuns.add(member)
16 | } else {}
17 | }
18 |
19 | // add annotated functions of all super-classes
20 | for (superclass in specClass.allSuperclasses) {
21 | collectCustomizerFuns<Any>(superclass, customizerFuns) <--- ERROR
22 | }
23 | }
I have been trying to fix these bugs for a while now, and would appreciate any help!
Also, please provide any constructive criticism you want regarding this function, it would help a lot!
For the first error, member.annotations returns List<Annotation>. You have to fetch actual classes of these annotations.
For the second error, remove the type where you call collectCustomizerFuns. Let kotlin infers the type by itself :).
So try this:
public tailrec fun <T: Any> collectCustomizerFuns(
specClass: KClass<T>,
customizerFuns: MutableList<KCallable<*>>
) {
// add annotated functions of this class
for (member in specClass.members) {
if (CustomizerFunction::class in member.annotations.map { it.annotationClass }) {
customizerFuns.add(member)
} else {
}
}
// add annotated functions of all super-classes
for (superclass in specClass.allSuperclasses ) {
collectCustomizerFuns(superclass, customizerFuns)
}
}
By the way, you can remove Unit from the method signature.

Get method called-as str in the callee

I would like to introspect the tail end of a method call from the callee side.
Right now I am doing this explicitly...
# caller side
s.pd: '.shape';
s.pd: '.to_json("test.json")';
s.pd: '.iloc[2] = 23';
# callee side
method pd( Str $call ) {
given $call {
when /shape/ { ... }
when /to_json/ { ... }
#etc
}
}
BUT, I would like to do this by way of a 'slang method call', something like this made up code...
# caller side
s.pd.shape;
s.pd.to_json("test.json");
s.pd.iloc[2] = 23;
^ ^^ ^^^^^^^^^^^^^^^^^^^$
| | |
| | L a q// str I can put into eg. a custom Grammar
| |
| L general method name
|
L invocant
#callee side
method pd( ?? ) {
my $called-as-str = self.^was-called-as;
say $called-as-str; #'pd.to_json("test.json")'
...
}
(HOW) can this be done in raku?
Since there are 422 calls to handle, of many arity patterns, answers that require the declaration of 422 methods and signatures in the called Class will be less attractive.
Per #jonathans comment, the raku docs state:
A method with the special name FALLBACK will be called when other
means to resolve the name produce no result. The first argument holds
the name and all following arguments are forwarded from the original
call. Multi methods and sub-signatures are supported.
class Magic {
method FALLBACK ($name, |c(Int, Str)) {
put "$name called with parameters {c.raku}" }
};
Magic.new.simsalabim(42, "answer");
# OUTPUT: «simsalabim called with parameters ⌈\(42, "answer")⌋␤»
So my code example would read:
# callee side
class Pd-Stub {
method FALLBACK ($name, Str $arg-str ) {
say "$name called with args: <<$arg-str>>"
}
}
class Series {
has Pd-Stub $.pd
}
my \s = Series.new;
# caller side
s.pd.shape; #shape called with args: <<>>
s.pd.to_json("test.json"); #to_json called with args: <<test.json>>
s.pd.iloc[2] = 23; #iloc called with args: <<>>
#iloc needs to use AT-POS and Proxy to handle subscript and assignment

Returning a boxed iterator over a value in a structure [duplicate]

This question already has answers here:
Why is adding a lifetime to a trait with the plus operator (Iterator<Item = &Foo> + 'a) needed?
(1 answer)
What is the correct way to return an Iterator (or any other trait)?
(2 answers)
Closed 5 years ago.
I want a function on a struct which returns an iterator to one of the struct's members. I tried something like the following, which doesn't work.
struct Foo {
bar: Vec<String>,
}
impl Foo {
fn baz(&self) -> Box<Iterator<Item = &String>> {
Box::new(self.bar.iter())
}
}
fn main() {
let x = Foo { bar: vec!["quux".to_string()] };
x.baz();
}
When compiling, I get the error below:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> src/main.rs:7:27
|
7 | Box::new(self.bar.iter())
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz(&self) -> Box<Iterator<Item = &String>> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:7:18
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that expression is assignable (expected std::boxed::Box<std::iter::Iterator<Item=&std::string::String> + 'static>, found std::boxed::Box<std::iter::Iterator<Item=&std::string::String>>)
--> src/main.rs:7:9
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^^^^^^^^^^^^^^^^^^
I also tried adding lifetime information as suggested elsewhere
struct Foo {
bar: Vec<String>,
}
impl Foo {
fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
Box::new(self.bar.iter())
}
}
fn main() {
let x = Foo { bar: vec!["quux".to_string()] };
x.baz();
}
Now my error is the following:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> src/main.rs:7:27
|
7 | Box::new(self.bar.iter())
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:7:18
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that expression is assignable (expected std::boxed::Box<std::iter::Iterator<Item=&std::string::String> + 'a>, found std::boxed::Box<std::iter::Iterator<Item=&std::string::String>>)
--> src/main.rs:7:9
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^^^^^^^^^^^^^^^^^^

How to highlight an Xtext cross-reference differently for targets of different types?

I have an Xtext grammar which reads (in part):
grammar mm.ecxt.MMLanguage hidden(WS, COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
...
Statement:
ConstantStatement |
VariableStatement |
LabeledStatement |
...
LabeledStatement:
EssentialHypothesisStatement |
...
ConstantStatement:
DOLLAR_C (constants+=ConstDecl)+ DOLLAR_DOT;
VariableStatement:
DOLLAR_V (variables+=VarDecl)+ DOLLAR_DOT;
EssentialHypothesisStatement:
name=LABEL DOLLAR_E (symbols+=[Decl|MATHSYMBOL])+ DOLLAR_DOT;
Decl: ConstDecl | VarDecl;
ConstDecl returns ConstDecl: name=MATHSYMBOL;
VarDecl returns VarDecl: name=MATHSYMBOL;
MATHSYMBOL: PARENOPEN | PARENCLOSE | QUESTIONMARK | COMPRESSED | TLABEL | WORD;
...
(The full grammar is MMLanguage.xtext from current commit 328a5e7 of https://github.com/marnix/metamath-eclipse-xtext/.)
My question: How do I highlight the symbols in an EssentialHypothesisStatement, by using a different color for constants and variables? So if the MATHSYMBOL refers to a ConstDecl, then it should be highlighted one way, and some other way for a VarDecl.
I've tried to create an ISemanticHighlightingCalculator in all kinds of ways, but I can't seem to detect what the actual reference type is, neither through the node model nor through the Ecore model. On the one hand, the grammar-related methods only tell me that the reference goes to a Decl. On the other hand, the Ecore model's EReferences tell me whether the target is a ConstDecl or a VarDecl, but there I can't find the location of the source MATHSYMBOL.
Note that I prefer to use the node model (as opposed to the Ecore model) since I also want to highlight comments, and for performance reasons I cannot afford multiple passes over the document.
What is a good/canonical/efficient/simple way to achieve this?
from EObject perspective have a look at org.eclipse.xtext.nodemodel.util.NodeModelUtils.findNodesForFeature(EObject, EStructuralFeature)
from the node model perspective you can use EObjectAtOffsetHelper
sample grammar
Model:
defs+=Def*
uses+=Use*
;
Def:
ADef | BDef;
ADef:
"adef" name=ID
;
BDef:
"bdef" name=ID
;
Use:
"use" def=[Def]
;
And here the Impl
public class MyDslSemanticHighlightingCalculator implements ISemanticHighlightingCalculator {
#Inject
private MyDslGrammarAccess ga;
#Inject
private EObjectAtOffsetHelper helper;
#Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor accoptor, CancelIndicator cancelIndicator) {
if (resource == null)
return;
IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootNode() == null)
return;
BidiTreeIterable<INode> tree = parseResult.getRootNode().getAsTreeIterable();
for (INode node : tree) {
if (cancelIndicator.isCanceled()) {
return;
}
if (node.getGrammarElement() instanceof CrossReference) {
if (ga.getUseAccess().getDefDefCrossReference_1_0() == node.getGrammarElement()) {
EObject target = helper.resolveElementAt(resource, node.getOffset());
if (target instanceof ADef) {
accoptor.addPosition(node.getOffset(), node.getLength(), HighlightingStyles.COMMENT_ID);
} else if (target instanceof BDef) {
accoptor.addPosition(node.getOffset(), node.getLength(), HighlightingStyles.STRING_ID);
}
}
}
}
}
}

Use trait from submodule with same name as struct

Trying to compile the following Rust code
mod traits {
pub trait Dog {
fn bark(&self) {
println!("Bow");
}
}
}
struct Dog;
impl traits::Dog for Dog {}
fn main() {
let dog = Dog;
dog.bark();
}
gives the error message
error[E0599]: no method named `bark` found for type `Dog` in the current scope
--> src/main.rs:15:9
|
9 | struct Dog;
| ----------- method `bark` not found for this
...
15 | dog.bark();
| ^^^^
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
|
1 | use crate::traits::Dog;
|
If I add use crate::traits::Dog;, the error becomes:
error[E0255]: the name `Dog` is defined multiple times
--> src/main.rs:11:1
|
1 | use crate::traits::Dog;
| ------------------ previous import of the trait `Dog` here
...
11 | struct Dog;
| ^^^^^^^^^^^ `Dog` redefined here
|
= note: `Dog` must be defined only once in the type namespace of this module
If I rename trait Dog to trait DogTrait, everything works. How can I use a trait from a submodule that has the same name as a struct in my main module?
You could rename the trait when importing it to get the same result without renaming the trait globally:
use traits::Dog as DogTrait;
The compiler now even suggests this:
help: you can use `as` to change the binding name of the import
|
1 | use crate::traits::Dog as OtherDog;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
documentation
If you don't wish to import both (or can't for whatever reason), you can use Fully Qualified Syntax (FQS) to use the trait's method directly:
fn main() {
let dog = Dog;
traits::Dog::bark(&dog);
}